Link to home
Start Free TrialLog in
Avatar of monica73174
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.  
Avatar of clarkscott
clarkscott
Flag of United States of America image

me.yourcombobox.text ??????
If you are using ADO data control, you can view the recordset value

adocontrol!comboboxfield

Scott C
Avatar of davecorun
davecorun

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
Avatar of monica73174

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.
Can you show us how you are binding the ComboBox, and setting DisplayMember and ValueMember?

Bob
combobox.selectedValue comes up blank.
i am using the dialog box in VS to bind the values.  
What is the DataSource set to?

Bob
The datasource says InstitutionBindingSource,  I think I created this through the combobox dialog box as well.  
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 ?
Yes both of those are selected and populated.  
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I switched the fields around and the value member is populating.
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 ?
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!