combo box item values - Possible?
-
hey, i am trying to assign values to my combo box items. I thought that as you add an item to a combo box you could also just add a value. I am having great trouble doing this. i have a datatable with a 'name' and 'id' column. i want the combo box to display the name but when it is selected to get the id. i currently have the following code
cmboConnections.DisplayMember = "name"
For i = 0 To connectionTable.Rows.Count - 1 If Not connectionTable.Rows(i).Item("name") Is Nothing Then cmboConnections.Items.Add(connectionTable.Rows(i).Item("name")) cmboConnections.ValueMember = connectionTable.Rows(i).Item("ID") End If Next
I am unable to find any property wher you can just combobox.SelectedItem.Value or combobox.Item(X).Value. Is there any way to set a value of a item in a combo box? Thanks for your help Chris
-
hey, i am trying to assign values to my combo box items. I thought that as you add an item to a combo box you could also just add a value. I am having great trouble doing this. i have a datatable with a 'name' and 'id' column. i want the combo box to display the name but when it is selected to get the id. i currently have the following code
cmboConnections.DisplayMember = "name"
For i = 0 To connectionTable.Rows.Count - 1 If Not connectionTable.Rows(i).Item("name") Is Nothing Then cmboConnections.Items.Add(connectionTable.Rows(i).Item("name")) cmboConnections.ValueMember = connectionTable.Rows(i).Item("ID") End If Next
I am unable to find any property wher you can just combobox.SelectedItem.Value or combobox.Item(X).Value. Is there any way to set a value of a item in a combo box? Thanks for your help Chris
I am now using a datatable cmboConnections.DataSource = connectionTable cmboConnections.DisplayMember = "name" cmboConnections.ValueMember = "ID" Which populates my combobox but i have no way of retrieving the Valuemember from the selectedIndexchanged event. Does anyone no how to get the ValueMember from a selected item? I have tried using the SelectedIndexChanged Event but the combobox.SelectedValue is a datarow and cannot be converted to string apparently? Any suggestions this is quite urgent Thanks for your help Chris