Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.Net 2010 - Retrieve MemberValue from ComboBox
    text
    copied!<p>I have been working on this for three days now and just can’t find a simple answer. (It really can’t be that hard to do surly). but now I can’t see the trees for the forest anymore.</p> <p>I populate a Combobox from an SQL database, this works fine and the data shows up fine in the Dataset Visualizer. </p> <p>ComboList is called cmbStateList</p> <p>Two Database fields DisplayMember “State” ValueMember “ID”</p> <p>What I want to do is simply return the ValueMember of when an item is selected from the combobox. When I use “cmbStateList.SelectedValue” in the cmbStateList_SelectedIndexChanged what is returned is the index or position of the item in the list, not the ValueMember (“ID”) field of the data.</p> <p>Here is the code I am using, really hope someone can help with this simple problem</p> <h2>Load the State List:</h2> <pre><code>SQL = "Select * from State" Command = New SqlCommand(SQL, CNN) DA.SelectCommand = Command DA.Fill(DS, "State") </code></pre> <h2>Bind the ComboBox:</h2> <pre><code>Me.cmbStateList.Items.Clear() Me.cmbStateList.DataSource = DS.Tables("State") Me.cmbStateList.DisplayMember = "State" Me.cmbStateList.ValueMember = "ID" </code></pre> <h2>Select the ComboBox (Have tried DropDownClosed and SelectedIndexChanged):</h2> <pre><code>Private Sub cmbStateList_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbStateList.SelectedIndexChanged MsgBox(Me.cmbStateList.SelectedValue) End Sub </code></pre> <p>Thanking you in advance Chris</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload