I am having problems sorting on multiple columns programmatically. I have 2 numeric columns, which I want to sort with one as a primary sort, and the other as a secondary sort.
I have a grid of about 1500 rows. Id is a unique numeric id column, and Type is a numeric column with (duplicate) values of 1, 2 or 3. I want the type to be the primary sort, and then sorted secondly by ascending id. This may be complicated by the fact that the type column is not visible, but I've tried making it visible to no noticeable difference.
I have tried the code from the help file :
grid.BeginInit();
try
{
grid.Columns.Items[0].SortOrder = SortOrder.Ascending;
grid.Columns.Items[1].SortOrder = SortOrder.Descending;
grid.Rows.Sort(grid.Columns.SortColumns);
}
finally
{
grid.EndInit();
}
However, on inspection, the "sortColumns" collection has a length of 1, and you don't get the expected result.
I have tried putting the two columns into an array, and then passing that array to the "sort" method, but that does not seem to work any better.
Any help, suggestions?