monica73174
asked on
comboboxes How to get the valuemember
I bound data to a combobox through the form provided. Why can I not retrieve the valuemember as a value and not the name of the data field. Maybe I am not understanding how the combobox works. Any help is appreciated.
If you want to get the value out of the ComboBox, you need to look at the SelectedItem or SelectedIndex. If I understand your question correctly.
Dim value As String = ComboBox1.SelectedValue
Bob
Bob
ASKER
I can grab me.yourcombobox.text but I also need the value that I gave it behind the sceenes.
I out put the name of an advisor but behind the sceenes I have the id of the advisor which is the value I need to grab. Wont SelectedIndex give me the index of the item in the combobox and not the value? And I think SelectedItem gives me a blank value. So is there something i am doing wrong with setting up the combobox?
in the dialog box for setting up the combobox I have my data source as InstitutionsBindingSource, my display member is masterName and the Value Member is mgr_id, Im not sure what to do with the selected value box.
So what do I use to grab the mgr_id value? If this is unclear let me know and i will try to explain it a different way.
I out put the name of an advisor but behind the sceenes I have the id of the advisor which is the value I need to grab. Wont SelectedIndex give me the index of the item in the combobox and not the value? And I think SelectedItem gives me a blank value. So is there something i am doing wrong with setting up the combobox?
in the dialog box for setting up the combobox I have my data source as InstitutionsBindingSource,
So what do I use to grab the mgr_id value? If this is unclear let me know and i will try to explain it a different way.
Can you show us how you are binding the ComboBox, and setting DisplayMember and ValueMember?
Bob
Bob
I think you will find some suggestion in here https://www.experts-exchange.com/questions/22747076/Combobox-question.html
ASKER
combobox.selectedValue comes up blank.
ASKER
i am using the dialog box in VS to bind the values.
What is the DataSource set to?
Bob
Bob
ASKER
The datasource says InstitutionBindingSource, I think I created this through the combobox dialog box as well.
ASKER
Is it better to just manually bind the combo box?
When you bind it you can chose the DisplayMember (the field that will show) and the ValueMember (the ID). Is that selected ?
ASKER
Yes both of those are selected and populated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I switched the fields around and the value member is populating.
ASKER
I mean the ID field is now in the display member and I can see them.
So right now if you select any Id from the combobox and try Combobox.SelectedValue what do you get ?
ASKER
Actually after I switched the fields and then swtiched them back its working. This is just strange.
Maybe your selection wasn't correct or missing something.
Sometimes it happens!
Sometimes it happens!
If you are using ADO data control, you can view the recordset value
adocontrol!comboboxfield
Scott C