Home Forums WinForms controls Xceed Grid for WinForms Sorting of Groups Reply To: Sorting of Groups

User (Old forums)
Member
Post count: 23064

You can try sorting the column on which the groups are grouped by. If the keys that are used to set the groups can sort in the order you want, this will resolve your issue. However, if these keys do not sort the way you want, then you will need to create your own keys in a way that they sort as you required.

To do this, you first need to handle the QueryGroupKeys event on the GridControl. In the handler, set your keys in a way they will sort as you which.

e.g.:

private void gridControl1_QueryGroupKeys(object sender, Xceed.Grid.QueryGroupKeysEventArgs e)
{
for( int i = 0; i < gridControl1.GroupTemplates.Count; i++ )
{
if( gridControl1.GroupTemplates[ i ].GroupBy == “City” )
{
string city = e.DataRow.Cells[ “City” ].Value as String;

if( city.CompareTo( “S” ) < 0 )
{
e.GroupKeys[ i ] = “A-K”;

}
else
{
e.GroupKeys[ i ] = “Other”;
}
}
}

This will produce two groups, one called A-K, one called Other. You can see the effect of sorting on the “City” column. Ascending will have A-K first, descending will have Other first. In you case, you need to find a key that will sort the group in the right order.

The problem is to know how many rows there is in each group. You need to know in advance the number of rows there is in each group, so you can set the e.GroupKey of the current DataRow to the required group key.

Imported from legacy forums. Posted by André (had 308 views)