Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Sorting in Virtual Mode

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Sorting in Virtual Mode
Link Posted: 13-Jun-2012 15:26
In Virtual Mode, when a user clicks on a header, I am setting the header to show as sorted by setting the SortOrder property.

However, this seems to make the grid actually attempt to sort all of the rows in the grid. Since the grid is virtual, and there are potentially hundreds of thousands of rows, this is a big problem (it is causing tons of calls to retrieve column values, which requires database queries to be executed, etc.).

I've tried preventing this by clearing data from the grid before setting the sort order, but it seems to want to sort the data when it is loaded.

Is there any way that I can have columns display as sorted, but not attempt to have virtual data be sorted in memory?

This is the WinForms version 1.5.7.0

Thanks
Link Posted: 14-Jun-2012 00:11
In virtual mode you can use your own sorting procedure, please look here for a solution of this problem.
Link Posted: 14-Jun-2012 10:29
Thanks - that more-or-less worked.

One note, though -- I had to remove a couple of calls to Rows.CollapseAll() that were in place to clean up data. Otherwise, those calls would end up calling through to a sort again, even though I was theoretically handling the sort.
Link Posted: 14-Jun-2012 12:33
Probably you can use flags to indicate the state when you enabled/disabled sorting:
dontSort = true;
try
{
  Rows.CollapseAll();
}
finally
{
  dontSort = false
}


and in sorting:
private void OnColumnSortOrderChanging(object sender, object column, SortOrder value, ref bool sorted)
{
  if (!dontSort)
   sorted = SortOnColumns(flyGrid.Columns.SortColumns);
}
Link Posted: 15-Jun-2012 00:26
That won't work -- I don't actually want to do any sorting at all - all I am doing in the sort method is saying that the rows are already sorted (which is true because they are coming back from SQL ordered).
Link Posted: 15-Jun-2012 05:24
In that case you can just modify sorted parameter:
private void OnColumnSortOrderChanging(object sender, object column, SortOrder value, ref bool sorted)
{
  sorted = true;
}
Link Posted: 15-Jun-2012 07:21
That is exactly what I am doing. However, calling CollapseAll() still causes a QuickSort.
Link Posted: 16-Jun-2012 07:48
We've found a workaround of this problem, please try to use the following code:
flyGrid.BeginUpdate(); //lock update, including sorting
try
{
  flyGrid.Rows.CollapseAll();
}
finally
{
  flyGrid.EndUpdate(); //unlock updates
}
Link Posted: 16-Jun-2012 13:48
That seems to work. Thanks.