New to Telerik UI for WinFormsStart a free 30-day trial

Improve GridView Sorting for Columns with Similar Values

Updated over 6 months ago

Environment

Product VersionProductAuthor
2022.3.913RadGridView for WinFormsDesislava Yordanova

Description

When RadGridView has a column in which most of the cells values are equal, the sorting seems to be slower than the case if the cells values are different with the same number of rows. This difference is observed due to the sorting algorithm that RadGridView internally uses.

Default sorting performance with 5000 records

improve-gridview-sorting 001

Solution

By default, if the rows count is less than 10 000 the grid uses quick sort to order the items. If there are more items, a Red-Black tree is used. This is controlled by the UseHybridIndex property.

It is known behavior that the quick sort exhibits poor performance for inputs that contain many repeated elements. That is why in order to get better performance, it is necessary to set the UseHybridIndex property to a smaller value:

C#

RadDataView<GridViewRowInfo> dataView = this.gridAdditionalTasks.GridViewElement.Template.ListSource.CollectionView as RadDataView<GridViewRowInfo>;
HybridIndex<GridViewRowInfo> indexer = dataView.Indexer as HybridIndex<GridViewRowInfo>;
indexer.Threshold = 500;

Improved sorting performance with 5000 records

improve-gridview-sorting 002

See Also