views:

548

answers:

1

Hi,

I have some requirement to implement a very non-standard sort in my data grid, the grid is currently bound to a DataView with the Original rows data row filter set, the data comes in realtime so i do an accept changes on a timer every second to show any changes made on the underlying data table. The grid is read-only, it's purely displaying realtime data.

For brevity i'll skip the details of the sorting. To solve this problem, I implemented some custom data view (read-only) that accepts a DataView as the source data (allowing me to still filter on row state and keep the virtual grid pattern for the realtime data). This collection / data view can be bound to the grid. My problem is keeping the custom data view's internal collection updated with any changes on the underlying data view. I tried at first to listen to the underlying data view's ListChanged event but even if i only add one row on the underlying data table and call accept changes I get the Reset event type meaning I have to refresh the whole collection - we could be talking about thousands of rows being refreshed (and re-sorted) just because of an update to a single row.

Anyone any experience with this before? I'm wondering how the grid does it, i know even if you give it a data table it's actually binding itself to the table's default view so does this mean that the data grid is reloading the whole collection of datarows from it's view even for a single row update?

Sorry for the long post!!

Appreciate any inputs, workarounds or even design alternatives...

Thanks Adrian

A: 

Depending on the type of grid you're using, it may be a simpler task to use that grid's built-in functionality for custom sorting (if there is one) rather than going down this road.

That being said, what is the reason behind always calling AcceptChanges on the DataTable? All that will do is set the RowState on all of the rows to Original, which shouldn't have any effect on what's being filtered and sorted through the DataView that you're using unless it has an active RowStateFilter.

If you take out the call to AcceptChanges (or even if you call it on the individual DataRow, rather than the DataTable itself), you should be able to use ListChanged.

Adam Robinson
Well, the sorting is a bit proprietry, i havent seen any grid that provides such functionality as of yet - to summarise the sorting, the user wishes the data to be sorted in a "group by" fashion where they can select a column to group by, followed by a column to sort by given a condition is first satisfied, any rows not satisfying the condition will be sorted using a simple multi column comparer, to do it it means i have to compare groups of rows hence the need for some kind of custom data view to handle this.
The AcceptChanges call is generally used when we have a DataView between the grid and the DataTable with some data DataViewRowState.OriginalRows, we almost always use DataViews when we are displaying data updated in realtime so the idea is that this custom data view can be plugged in between the dataview and the grid to enable this sorting. The only way I know would be to take a DataTable instead of a DataView but then we don't get the option of using a DataViewRowState which is required for a lot of applications. How could I utilise the DataViewRowState in my own data view...
There won't be any grid that provides the *specific* sorting functionality that you describe. There are plenty of grids, however, (though the DataGridView is not among them as far as I know) that provide the user (you) the ability to sort rows any way they see fit, usually through an event model. In general, the grid raises an event, passes two rows to you, and you return a standard comparison value (-1, 0, or 1) to compare the rows for the grid. Is there some particular reason that you do **not** want any rows other than DataRowState.Original to display?
Adam Robinson
we are using some in-house built data grid we call hyper grid which is a very basic datagrid, we do use infragistics grids mostly but anything performance critical and high volume we use our in house cut down grid it's also used to display cube data, by that I mean something like a pivot table in excel. So any advanced grid sorting functionality is out of the window unfortunately, that said, infragistics is pretty powerful but i havent seen a way to implement this even if i were using their grid...
As for the row state, I'm not sure for what purposes we use it in some of our apps, I can probably get away without the DataRowState but it would still be nice to base my view off a DataView rather than a table just for increased flexibility, not only would I get that should i require it sometime in the future but I also get filtering for free should I wish to use it. Anyway seems like it's not so trivial after all, I might just end up basing my view on a data table to keep it simple...
Well, even if you require the RowState to be Original, all you have to avoid is calling AcceptChanges on the table, call it on the individual rows. Calling it on the table will trigger a Reset, whereas the individual rows should not.
Adam Robinson