473,804 Members | 3,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any way to have a ListBox with nothing selected?

I need to have a control (currently trying to use listbox) where the user
can have nothing selected if they choose. Any way to do that with a list box
or would I be better off with a RadioButtonList ? Any other bound controls I
should look into?

Thanks!
Nov 18 '05 #1
7 5957
deselect the listbox by setting the selectedindex to -1 in code

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"MattB" <so********@yah oo.com> wrote in message
news:2m******** ****@uni-berlin.de...
I need to have a control (currently trying to use listbox) where the user
can have nothing selected if they choose. Any way to do that with a list
box
or would I be better off with a RadioButtonList ? Any other bound controls
I
should look into?

Thanks!

Nov 18 '05 #2
Usually easiest done by adding an empty item at position zero after binding,
at leat that way the user can select nothing as an option

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"MattB" <so********@yah oo.com> wrote in message
news:2m******** ****@uni-berlin.de...
I need to have a control (currently trying to use listbox) where the user
can have nothing selected if they choose. Any way to do that with a list box or would I be better off with a RadioButtonList ? Any other bound controls I should look into?

Thanks!

Nov 18 '05 #3
Alvin Bruney [MVP] wrote:
deselect the listbox by setting the selectedindex to -1 in code
I need to have a control (currently trying to use listbox) where the
user can have nothing selected if they choose. Any way to do that
with a list box
or would I be better off with a RadioButtonList ? Any other bound
controls I
should look into?

Thanks!


Thanks to you both!

Matt
Nov 18 '05 #4
Hi, just wondering how to add an empty item at position 0 after data binding as I have a listbox that is currently setup with a databind, after using a stored procedure to fill a dataset?
Thanks.
--
Paul G
Software engineer.
"John Timney (Microsoft MVP)" wrote:
Usually easiest done by adding an empty item at position zero after binding,
at leat that way the user can select nothing as an option

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"MattB" <so********@yah oo.com> wrote in message
news:2m******** ****@uni-berlin.de...
I need to have a control (currently trying to use listbox) where the user
can have nothing selected if they choose. Any way to do that with a list

box
or would I be better off with a RadioButtonList ? Any other bound controls

I
should look into?

Thanks!


Nov 18 '05 #5
I agree with John on the the empty item for the scenario if a user selects and item and decides to not select something, then the listbox would save that item selected. This would not leave the user a choice unselect their initial choice.
"John Timney (Microsoft MVP)" wrote:
Usually easiest done by adding an empty item at position zero after binding,
at leat that way the user can select nothing as an option

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"MattB" <so********@yah oo.com> wrote in message
news:2m******** ****@uni-berlin.de...
I need to have a control (currently trying to use listbox) where the user
can have nothing selected if they choose. Any way to do that with a list

box
or would I be better off with a RadioButtonList ? Any other bound controls

I
should look into?

Thanks!


Nov 18 '05 #6
With ddlRoutes
.DataSource = travelDB.GetRou tes
.DataTextField = "RouteName"
.DataValueField = "RouteID"
.DataBind()

.Items.Insert(0 , New ListItem("-select route-", ""))
End With

HTH,
Greg

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:A6******** *************** ***********@mic rosoft.com...
Hi, just wondering how to add an empty item at position 0 after data binding as I have a listbox that is currently setup with a databind, after
using a stored procedure to fill a dataset? Thanks.
--
Paul G
Software engineer.
"John Timney (Microsoft MVP)" wrote:
Usually easiest done by adding an empty item at position zero after binding, at leat that way the user can select nothing as an option

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"MattB" <so********@yah oo.com> wrote in message
news:2m******** ****@uni-berlin.de...
I need to have a control (currently trying to use listbox) where the user can have nothing selected if they choose. Any way to do that with a
list box
or would I be better off with a RadioButtonList ? Any other bound
controls I
should look into?

Thanks!


Nov 18 '05 #7
ok thanks it worked!
--
Paul G
Software engineer.
"Greg Burns" wrote:
With ddlRoutes
.DataSource = travelDB.GetRou tes
.DataTextField = "RouteName"
.DataValueField = "RouteID"
.DataBind()

.Items.Insert(0 , New ListItem("-select route-", ""))
End With

HTH,
Greg

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:A6******** *************** ***********@mic rosoft.com...
Hi, just wondering how to add an empty item at position 0 after data

binding as I have a listbox that is currently setup with a databind, after
using a stored procedure to fill a dataset?
Thanks.
--
Paul G
Software engineer.
"John Timney (Microsoft MVP)" wrote:
Usually easiest done by adding an empty item at position zero after binding, at leat that way the user can select nothing as an option

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"MattB" <so********@yah oo.com> wrote in message
news:2m******** ****@uni-berlin.de...
> I need to have a control (currently trying to use listbox) where the user > can have nothing selected if they choose. Any way to do that with a list box
> or would I be better off with a RadioButtonList ? Any other bound controls I
> should look into?
>
> Thanks!
>
>


Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2770
by: Alienz | last post by:
I have a subform where I have a subform with 20 options to select from. When I set the multiselect property to simple and select multiple options, nothing is stored. I have another table with fieldID and fieldtype and I would like for evertime something is selected in the listbox for a new entry to be created with that fieldtype for the corresponding fieldID which is linked to the main form. Basically, how do I get info from the listbox...
2
6368
by: Sally | last post by:
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I want to do this as the selections are being made not after-the-fact after all selections are made. Thanks! Sally
2
2916
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However, currently the code is such that with each selection there is a postback. We want to avoid it using filter and javascript. I am not using ADO.NET but adodbc and no datagrids or datasets (please don't tell me that i should as my boss clearly doesn't want...
6
2884
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
4
2465
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item, what do I need to do in order to return the "option value" of the control? Moe !--- returned value of the control
4
1861
by: collie | last post by:
HI, I need to populate 2 listboxes from a db. When the page loads then the first listbox needs to be populated and based on selection from that listbox the second listbox needs to be populated accordingly with the matching items. However, my boss doesn't want the page to do a postback once an item from the first listbox is selected. also, he doesn't want to use ado.net but classic ado. He wants to use jscript. I am writing my code in...
11
8558
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to the array list again to refresh. Click on an item in the list, and an Indexing error comes up. (in non-user code, it is trying to get an element from the array that is greater than the number of items in the array.) To reproduce:
2
6321
by: php_Boi | last post by:
i have designed an application that is a dynamic submission form. i have text fields and listboxes. now i am able to retain the values of the listboxes when i populate the listbox "manually"(single listbox) like this... <select name="title"> <option value="1"<?php if ($_POST == '1') { echo 'selected="selected"'; } ?>></option> <option value="Mr"<?php if ($_POST == 'Mr') { echo 'selected="selected"'; } ?>>Mr</option>
9
3250
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback). This listbox has AutoPostback = True. When the user selects an item from this list, the second listbox is populated with more items relevant to this selection. I am using an SQLDataSource web control for this. These items are headers. I want, when...
1
12887
by: dkohel | last post by:
I have 2 list boxes on my form. I am trying to populate listbox B with the selection from listbox A. I have set multi-select in both boxes to Extended... The user will select the items from listbox A and click an Add button that will then copy the items to listbox B. Then for each item in B, I need to add them to a database. If there are 3 items in listbox B, I need to add 3 line items to table B... Any ideas?
0
9571
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.