Cindy,
Another option is to construct a RowFilter that just the
desired rows satisfy. Say you want to display customers sorted
by country, along with the ability to show just a page of rows
(#11 - #20) in the DataView. First, set the DataView's Sort
property to Country plus CustomerID so there's a definite order:
vue.Sort = "Country, CustomerID"
When I look at customer #11 in this view, the country is
Brazil and the CustomerID is HANAR. So, if I want to view
customer #11 and greater, I would set the RowFilter property to:
"Country > 'Brazil' OR (Country = 'Brazil' AND CustomerID >=
'HANAR')"
Customer #20 is in Denmark with a CustomerID of SIMOB. A
RowFilter to view just the customers up to #20 would be:
"Country < 'Denmark' OR (Country = 'Denmark' AND CustomerID <=
'SIMOB')"
Now, you can combine these filters, add parenthesis, and add
calls to the desired rows in the DataView to get code like the
following, and I apologize ahead of time for the inevitable
problem with line breaks.
VB.NET:
Dim rowFirst, rowLast As DataRowView
rowFirst = vue(10)
rowLast = vue(19)
vue.RowFilter = string.Format("(Country > '{0}' OR (Country =
'{0}' AND CustomerID >= '{1}')) AND (Country < '{2}' OR (Country
= '{2}' AND CustomerID <= '{3}'))", rowFirst("Country"),
rowFirst("CustomerID"), rowLast("Country"), rowLast("CustomerID"))
C#:
DataRowView rowFirst, rowLast;
rowFirst = vue[10];
rowLast = vue[19];
vue.RowFilter = string.Format("(Country > '{0}' OR (Country =
'{0}' AND CustomerID >= '{1}')) AND (Country < '{2}' OR (Country
= '{2}' AND CustomerID <= '{3}'))", rowFirst["Country"],
rowFirst["CustomerID"], rowLast["Country"],
rowLast["CustomerID"]);
Not exactly elegant, but quite effective.
I hope this information proves helpful.
David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.