Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
762
Specify WinGrid sort column programmatically.
posted

We have an old WinForms app with a .NET Advantage 2009 UltraWinGrid control. The default sort column was specified in the Design view, but now we have a requirement to save the user's sort order and restore it when relaunching the app.

We can get the last sort order in the Form_Close event with:

var gridSort = _ourGrid.DisplayLayout.Bands[0].SortedColumns[0];
SettingsFile.Save(gridSort.Key, (int)gridSort.SortIndicator);

And the correct values are stored in the Settings file, but nothing seems to restore the sort order to the grid. We have tried code like:

string columnName;
SortIndicator columnSort;
SettingsFile.Load(out columnName, out (int)columnSort);

var ourGridSort = _ourGrid.DisplayLayout.Bands[0].SortedColumns;
ourGridSort.Clear();
ourGridSort.Add(columnName, columnSort);
_ourGrid.DisplayLayout.Bands[0].SortedColumns.RefreshSort(true);

In the Form_Load, but this has no effect on the grid, it remains sorted by the original default.