I got a bounded combobox to a group name in vb.net. i can view in the drop down items of the combobox the set of GROUP NAMES. but when i do an insert or update query, i need to make the selected group name refers to the GROUP NUMBER. I don't want to store letters in the database, instead i prefer numbers. how can i do that?!
Here is my code so far :
cmd1.Parameters.AddWithValue("@group", DirectCast(Additemcombobox.SelectedItem,
DataRowView).Item("GroupName"))
Storing the group name in database is currently working well.
My question might not be well explained. Please ask me in case... any help would be appreciated
You can show one element to the user such as the name, but use a different one for the code to identify the item using
DisplayMember
andValueMember
The user will only see the names, while the code can use
ValueMember
:It prints the Group ID not the name. Depending on the ORDER BY clause in the SQL and the ID, the
SelectedIndex
may or may not match, so respond toSelectedValueChanged
event. If you useSelectedValue
instead ofSelectedItem
you wont have to thrash about with aDataRowView
item.Note that
SelectedValue
isObject
so you will have to cast to integer or whatever for use elsewhere.