Combobox ValueMember Value

I'm having a hard time figuring out how to reference the value of the ValueMember property of a combobox.  I'm using a dataset that I pull from a sql server; i'm able to get the text for the DisplayMember ok, but when I try to display the ValueMember it just gives me "fid".
 
How do I display the value associated with ValueMember?


        Dim conFrequencies As New SqlConnection(conStringFrequencies)
        Dim daFrequencies As New SqlDataAdapter(strSQLFrequencies, conFrequencies)
        Dim dsFrequencies As New DataSet
        daFrequencies.Fill(dsFrequencies, "Frequencies")

        With cboFrequencies
            .DisplayMember = "name"
            .ValueMember = "fid"
            .DataSource = dsFrequencies.Tables("Frequencies")
            .SelectedIndex = 0
        End With
LVL 1
vbNewbie2009Asked:
Who is Participating?
 
Imran Javed ZiaConnect With a Mentor Consultant Software Engineer - .NET ArchitectCommented:
You cannot display ValueMember item but you can get value of selected item as cboFrequencies.SelectedValue

if you want something like multivalue display then think about ListView or some other control.
0
 
edemcsCommented:
verify that that column exists.  Its most likely not in the Table as fid.
0
 
hongjunCommented:
what is value of strSQLFrequencies?
make sure you are selecting both fid and name.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
vbNewbie2009Author Commented:
The value of strSQLFrequencies is:
Dim strSQLFrequencies As String = "select fid, name from frequencies order by name"

I really don't care to see multi value's in the control, just wanted to be able to show a sensible name to the user they could pick but use the id of the selection instead of the name.  Maybe this is the wrong approach?

0
 
hongjunCommented:
what happen if you run the sql in mssql management studio? is name filled or empty?
0
 
vbNewbie2009Author Commented:
it is filled; just a simple table for now, but this is the results:

fid      name
1      10 DAY
2      20 DAY
4      MONTHLY
3      PER FILL
0
 
vbNewbie2009Author Commented:
Using cboFrequencies.SelectedValue worked!  Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.