C# Custom DataView

C# Custom DataView

Ask Question

10 years, 6 months ago

9 years, 5 months ago

2k times




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…


c# datatable dataview

share|improve this question

asked Sep 15 ’09 at 14:33


add a comment

1 Answer





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.

share|improve this answer

answered Sep 15 ’09 at 14:40

Adam RobinsonAdam Robinson

161k2929 gold badges260260 silver badges325325 bronze badges

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.

– Adrian
Sep 15 ’09 at 15:52

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…

– Adrian
Sep 15 ’09 at 16:04

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
Sep 15 ’09 at 16:20

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…

– Adrian
Sep 15 ’09 at 16:52

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…

– Adrian
Sep 15 ’09 at 16:54

show 1 more comment

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password


Post as a guest


Required, but never shown

Post Your Answer


By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

The Overflow Blog

Podcast Episode 220: Fully Remote

Tracking down performance pitfalls in Vue.js

Featured on Meta

Planned maintenance scheduled for Saturday, March 28, 2020 at 13:00 UTC (9AM…

An Update On Creative Commons Licensing

Community and Moderator guidelines for escalating issues via new response…

How does the Triage queue work?

Triage needs to be fixed urgently, and users need to be notified upon…


1833How do I calculate someone’s age in C#?1496Calculate relative time in C#6421What is the difference between String and string in C#?1848What is the best way to give a C# auto-property an initial value?2497What are the correct version numbers for C#?2174How do I get a consistent byte representation of strings in C# without manually specifying an encoding?1783Get int value from enum in C#2.Net DataView and DataTable Binding1How to update only one row in DataView from SQL database?

Hot Network Questions

Did Russia release lions onto the streets to keep people in isolation?

Has radio astronomy ever been done on objects that appear very close to the Moon? Is this avoided?

Why is the effect called Dodge?

When we press a piano key, why does a high pitch note not run for as long as a low pitch note?

Ranged-attack initiative and sequencing for monsters and NPCs

Word for a small cylindrical glass container (for salves, creams etc.)

Are force vectors members of a vector space?

Sci-fi short story about extra sense that can be experienced by humans only once (probably from 1960’s or 70’s)

Is it common to have no MathSciNet version of a paper in Mathematics?

When I burn isopropyl alcohol (IPA), it burns orange. But when I burn ethyl alcohol, it burns totally blue. Why is this?

Why does camouflage make some planes fly slower?

What should I call a “differential” which cubes, rather than squares, to zero?

Confused with the effect number of decimals at the output of transducer

How do “tip jet” helicopters cancel the torque effect of the main rotor?

Why should one pre-heat an oven?

Could Byzantines Bridge a Deep Strait Separating 2 Continents?

Why would a ‘first world’ alien opt to have a brood of dumb children rather than one smart one?

Football Rivals

How to make bread with plain flour?

Why don’t laws have examples?

Drawing the following two matrices

Chair Offers COVID-19 Compensation… But Asks ME to Put Out a Number

How do you cross-breed flowers?

Water temperature in upper shower

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


Leave a Reply

Your email address will not be published. Required fields are marked *