Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > ComboBox ValueMember Binding Issue
 

ComboBox ValueMember Binding Issue

I have a combo box which i have set the Valuemember to a column.  What seems to be showing up is the column name, not the data value.  Am I doing this wrong?
Thanks,
MikeD

Here is what I did to check it.

private void cbQuery_SelectedIndexChanged(object sender, EventArgs e) {
if (this.cbQuery.Text == "")
   return;
MessageBox.Show("vm=" + this.cbQuery.ValueMember.ToString());
}




 

Mike D  Wednesday, September 07, 2005 7:26 AM

You want to use SelectedValue rather than ValueMember.  By selecting the valuemember you are simply asking the combo for the name of the valuemember rather than the value of the value member.  Does this make sense?

eg.

your above code should read something along the lines of

private void cbQuery_SelectedIndexChanged(object sender, EventArgs e) {
if (this.cbQuery.Text == ""
)
   return;
MessageBox.Show("vm=" + cstr(this.cbQuery.SelectedValue);
}

Mark_Evans  Wednesday, September 07, 2005 9:36 AM

You want to use SelectedValue rather than ValueMember.  By selecting the valuemember you are simply asking the combo for the name of the valuemember rather than the value of the value member.  Does this make sense?

eg.

your above code should read something along the lines of

private void cbQuery_SelectedIndexChanged(object sender, EventArgs e) {
if (this.cbQuery.Text == ""
)
   return;
MessageBox.Show("vm=" + cstr(this.cbQuery.SelectedValue);
}

Mark_Evans  Wednesday, September 07, 2005 9:36 AM
Thanks,Mark.  I had a 'dah' moment;

MikeD
Mike D  Wednesday, September 07, 2005 12:46 PM

You can use google to search for other answers

Custom Search

More Threads

• How to make a Unbound Textbox Null into a db?
• How to force the sorting glyph to show?
• How to get the selected value of a combo box ?
• Need some Datagrid help
• RadioButton in DataGridView (VB.net 2005 Express)
• Using a DB transaction with generated code in a QueriesTableAdapter
• Update Database Value from Text Box
• vb.net datagridview
• Format dataGridview column
• sql server instances list