ComboBox ValueMember

J

Jim Heavey

If you have a comboBox which has it's DisplayMember and ValueMenber bound
to a datatable.

If I know the "ValueMember" value - is there a way for me to set
the index of the control to correspond to that ValueMember without having
to iterate over the values in the control to find the index of the matching
value menber?

There is a "FindString" method of the ComboBox which apparently iterates
over the collection looking form a match on the "DisplayMember", but there
does not seem to be a method which works on "ValueMember". Is that
correct?
 
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

Hi Jim,
If you have a comboBox which has it's DisplayMember and ValueMenber bound
to a datatable.

If I know the "ValueMember" value - is there a way for me to set
the index of the control to correspond to that ValueMember without having
to iterate over the values in the control to find the index of the matching
value menber?

There is a "FindString" method of the ComboBox which apparently iterates
over the collection looking form a match on the "DisplayMember", but there
does not seem to be a method which works on "ValueMember". Is that
correct?

I've found in .NET docs a ComboBox's property: SelectedValue
Its description says: Gets or sets the value of the member property
specified by the ValueMember property.

I've hadn't tested it but you can do it and test it's work.

Regards

Marcin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top