• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1621
  • Last Modified:

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
0
vbNewbie2009
Asked:
vbNewbie2009
1 Solution
 
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
 
Imran Javed ZiaCommented:
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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now