I found the WinGrid Performance Guide very helpful, but I also have another question on this subject: does the type of DataSource affect WinGrid performance, and if yes, how? For example, lets say I have a large set of data that changes very often (e.g. market data), and I have a choice as to which DataSource to use - a DataTable or a BindingList, what are the tradeoffs here?
Thank you,Dmitriy
Hi Mike, would you please give me more detail on the Binding<T> as data-source. I have a problem for this, I have got another post here. Performance Issue on multiple bands - Grid and datasource
Mike, thanks for the detailed reply, this is all very helpful
Hi Dmitriy,
That's an excellent question.
To be fair, what you really talking about here is not actually the performance of the grid, but rather the performance of the data source. Since the grid accesses the data source very frequently, though, the data source can certainly have an impact on the performance of the grid.
Let's take your example of a DataTable vs. a BindingList in a case where you have a large amount of data. Since you said DataTable, not DataSet, I'm assuming the data source is flat - there are no child bands. I haven't done any testing on this, but I suspect there would not be much difference in performance between the two in this case. If there is a difference, then my guess is that BindingList might be a bit more efficient. One reason for this is that BindingList data is typed. Another is that the BindingList doesn't have to deal with the possibility of adding columns at run-time. The columns are defined at compile-time and cannot be changed later. So there's a certain lack of flexibility there, but the BindingList can make assumptions about the consistency of the data schema that the DataTable cannot and that may make it more efficient.
Comparing DataSets and Hierarchical BindingLists<T> would be more complicated. Once you introduce child bands, the DataSet can become pretty inefficient. This is because a child row can change parents based on Relations. One big performance hit that the grid often encounters is the retrieval of child rows in a DataSet. When you have parent row in a DataSet and you ask for the child rows, the BindingManager basically has to loop through every row in the child band to determine which rows meet the criteria of the Relation to find the child rows.
This is, in fact, why the grid's ExpansionIndicator property defaults to CheckOnExpand. By default, the grid displays an expansion indicator on every row that might have children. It doesn't check for the child rows until you actually attempt to expand the row because simply checking for the existance of child rows can be an expensive operation with some data sources.
A BindingList<T> can do this much more efficiently, because it will usually keep a simple list of child rows - it doesn't have to loop through all child rows in the entire child band.
The trade-off here is that the DataSet is more flexible for displaying relational data. You could change a foreign key in a child row to "move" that row under a different parent. The down side is that relational data is slower to retrieve.