|
-
Oct 10th, 2005, 06:44 AM
#1
Thread Starter
Fanatic Member
combobox
hi,
I would like to populate a comboBox with three text values and assign an ID to each one so that when one of them is selected, then an ID for that text value is used later on
ie.
combobox1.items.add("value1")
combobox1.items.add("value2")
combobox1.items.add("value3")
tried
accountTypeComboBox.Items.Add (new ListItem("Item 1", "0"))
accountTypeComboBox.Items.Add (new ListItem("Item 2", "1"))
but gives an error on ListItem
Thanks
Last edited by fmardani; Oct 10th, 2005 at 06:54 AM.
-
Oct 10th, 2005, 06:47 AM
#2
Re: combobox
use the index value instead of the text property.
-
Oct 10th, 2005, 06:54 AM
#3
Thread Starter
Fanatic Member
Re: combobox
 Originally Posted by Phill64
use the index value instead of the text property.
But I would like to have the text to be shown and the ID to be retrieved when an item is selected.
Thanks
-
Oct 10th, 2005, 07:12 AM
#4
Re: combobox
ComboBox1.SelectedIndex
this will give you the index (eg: ID) of the selected item in ComboBox1
it's as simple as that
-
Oct 10th, 2005, 07:16 AM
#5
Thread Starter
Fanatic Member
Re: combobox
 Originally Posted by Phill64
ComboBox1.SelectedIndex
this will give you the index (eg: ID) of the selected item in ComboBox1
it's as simple as that
How do you know which ID is assigned to which text when populating...
please note the IDs are 1,2,3
they do not start from 0
Thanks
-
Oct 10th, 2005, 01:45 PM
#6
Re: combobox
then "id = combobox1.selectedindex + 1"....
-
Oct 10th, 2005, 07:38 PM
#7
Re: combobox
 Originally Posted by fmardani
But I would like to have the text to be shown and the ID to be retrieved when an item is selected.
Thanks
Create a datatable then bound it to the combobox.
i.e
VB Code:
combobox1.datasource=mytable
combobox1.displaymember="name" <---column name of your datatable
combobox1.valuemember="id" <---column name of your datatable
When you select an item the returning value is the id that correspand to the name.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|