One datasource, two combo boxes, two different sorts

  • Thread starter Thread starter Diane Yocom
  • Start date Start date
D

Diane Yocom

I'm looking for ideas on how to populate two different combo boxes with one
datasource that is sorted in two different ways. The combo boxes will use
the same field for the value field, but display different fields. I'd like
the combo boxes to sort on their display field.

Requerying the database to create a second datasource is not an option.

I've tried cloning the datatable so I can sort the defaultview two different
ways, but datatable.clone is only a shallow clone, so I don't get the rows.

Any other suggestions?
Diane Y.
 
I'm looking for ideas on how to populate two different combo boxes with one
datasource that is sorted in two different ways. The combo boxes will use
the same field for the value field, but display different fields. I'd like
the combo boxes to sort on their display field.

Requerying the database to create a second datasource is not an option.

I've tried cloning the datatable so I can sort the defaultview two different
ways, but datatable.clone is only a shallow clone, so I don't get the rows.

Any other suggestions?
Diane Y.

Hi Diane,

You can do this with a DataSource, but I don't think you can do this with a DataSet/DataTable as DataSource. Having each combobox sort differently might indicate the relationship between the fields are not necessary, in which case you could easily create two lists instead and have the selected item map to some object.
 
I'm looking for ideas on how to populate two different combo boxes with one
datasource that is sorted in two different ways. The combo boxes will use
the same field for the value field, but display different fields. I'd like
the combo boxes to sort on their display field.

Requerying the database to create a second datasource is not an option.

I've tried cloning the datatable so I can sort the defaultview two different
ways, but datatable.clone is only a shallow clone, so I don't get the rows.

There is a DataView between the DataTable and the bound control. By
default this is a DataView supplied by the DataTable
(DataTable.DefaultView). The sorting is done in the DataView.

You can create another DataView and use it for the second combo box.
There is an example in the MSDN documentation for DataView at
<http://msdn2.microsoft.com/en-us/library/system.data.dataview.aspx>.
 
I tried creating a new dataview with the following line:

Dim dvSorted as new dataview(mydataset, "", "SortFieldName",
DataViewRowState.None)

I then set the datasource of one of the combo boxes to dvSorted.
Unfortunately, it's not sorted by the field that I specified. It's sorted
the same way it came out of the database.

What am I missing here?
 
Correction, my line of code is this:

Dim dvSorted as new dataview(mydataset.tables(0), "", "SortFieldName",
DataViewRowState.None)
 
Back
Top