Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataView.Sort and DataView.FindRows

Status
Not open for further replies.

ByteMyzer

Programmer
Nov 17, 2002
201
0
0
US
thread732-333932

iamanson said:
Hi,
If my DataView contains data
ID VALUE
APPLE 1
APPLE 3
APPLE 2
ORANGE 1
ORANGE 4
ORANGE 2
ORANGE 3

Can I use .FindRows to get DataRowView data ID=ORANGE and sorted by VALUE?

I tried
DataView.Sort="ID, VALUE";
DataRowView [] = DataView.FindRows("ORANGE");
but it's not a valid syntax.

I realize that this is in reference to an old thread, but since it comes up on a search, and since someone else may have the same question to be answered, here it is:

You can not define a sort with multiple fields on a DataView and execute the FindRows method using a key that only has some of the fields in the sort key. Going by the provided example, the data must first be sorted in the underlying DataTable, thus:
Code:
ID    VALUE
APPLE   1
APPLE   2
APPLE   3
ORANGE  1
ORANGE  2
ORANGE  3
ORANGE  4

Then, the sort should be on the one field that is required for the FindRows operation, thus:
Code:
myDataView.Sort = "ID";
DataRowView[] myDataRowView = myDataView.FindRows("ORANGE");

The VALUE field in this example will still retain its sorting order from the DataTable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top