Data-bound control- Syncing selected with data search

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
 
M

Munir Husseini

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
 

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