Data-bound control- Syncing selected with data search

  • Thread starter Thread starter kadams1
  • Start date Start date
K

kadams1

Greetings:

I'm have a WinForm in VB.Net that has several simple controls,
specifically Comboboxes, that are data bound. I want to perform a search
on the bound data (NOT on the values in the Combobox), find a particular
row in the Dataset, and make the corresponding entry in the Combobox
become selected.

A Dataset.<tablename>.Rows.Find returns a DataRow. Combobox.SelectItem
expects a DataRowView, so that won't work. And unless I'm missing
something, there is no Combobox.Find that will search on arbitrary fields
in the datasource.

I can see kludgy ways to do this, for example using the data from the row
returned by the search to create a value string that can be used to search
the Combobox. But this is not only inelegant, it could be downright wrong
in the situation where the values displayed in the combobox are, for
example, not unique to the data rows.

Thoughts?

Kelly
 
Am Tue, 31 May 2005 13:13:07 -0700 schrieb (e-mail address removed):
Greetings:

I'm have a WinForm in VB.Net that has several simple controls,
specifically Comboboxes, that are data bound. I want to perform a search
on the bound data (NOT on the values in the Combobox), find a particular
row in the Dataset, and make the corresponding entry in the Combobox
become selected.

A Dataset.<tablename>.Rows.Find returns a DataRow. Combobox.SelectItem
expects a DataRowView, so that won't work. And unless I'm missing
something, there is no Combobox.Find that will search on arbitrary fields
in the datasource.

I can see kludgy ways to do this, for example using the data from the row
returned by the search to create a value string that can be used to search
the Combobox. But this is not only inelegant, it could be downright wrong
in the situation where the values displayed in the combobox are, for
example, not unique to the data rows.

Thoughts?

Kelly

Hi Kelly,

this is just a guess, but maybe something like this could do the trick:
Assuming your datarow is called dr and a column called "id" is it's key...

DataRow dr = ...;
DataRowView[] drv = dr.Table.DefaultView.FindRows(dr["id"]);
comboBox1.SelectedItem = drv[0];

Hope this helps.

Regards,
Munir Husseini
 
Back
Top