If you develop WinForms or WebForms clients that consume webservices, and
display the results in a DataGrid, you may be interested in a helper class I
found recently. It is the CollectionView class described at:
http://dotnetjunkies.com/WebLog/bsbl.../02/24116.aspx
This can help with sorting and filtering of collections, when displayed in a
DataGrid.
A DataGrid is a powerful data display widget. One of the interesting things
you can do when binding a DataSet (data retrieved from a Data source like
Oracle, DB2, SQL Server) to a DataGrid for display, is filter and sort the
data to be displayed, through the DataView class.
Filtering and sorting is not so straightforward when binding a collection of
arbitrary objects to the DataGrid. This CollectionView helper class
provides the analog to the DataView, but for arbitrary collections.
Nice !
Example: suppose you retrieve 10,000 records from a web service. You now
have an array of typed objects. You can bind these to a DataGrid to display
the information, one row to an item in the array, one column for each field
in the base object type. But if you want to display, for example, only the
records that end in Odd numbers, or only the records that include
international addresses, or etc etc... that's tricky. If you want to sort
on various columns, that's also tricky. Doing both at the same time is
very tricky. The CollectionView lets you do these things.
I modified a few things from Brendan's code (which itself is a derivative of
Rocky Lotka's example)
- added filters for "Includes" and "NotIncludes"
- better support for filtering and sorting at the same time
- caching property descriptors (for performance)
here is the modified source
http://cheeso.members.winisp.net/src...lectionView.cs
here is an example showing its use (scenario: IE Cache Viewer, not
webservices client):
http://cheeso.members.winisp.net/dl/...-2005Jan06.zip
Enjoy,
-Dino
--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ OmitThis . m i c r o s o f t . c o m