User (Old forums)MemberOctober 19, 2006 at 6:10 pmPost count: 23064
I can’t seem to find an answer to this, but I will try to explain what I am attempting to do.
I have a grid control that allows for users to drag and drop columns for grouping. I get the groups displayed but the groups are not in an ascending order by the number of items that are in each group. Is there a way to sort the groups by the quantities that each group holds?
Group 1 – 1000 items
Group 2 – 2000 items
Group 2 – 2000 items
Group 1 – 1000 items
I really don’t care about the sorting within the the groups, I would just like to sort and display the groups by the number of items that each group holds.
Imported from legacy forums. Posted by TParker (had 2998 views)User (Old forums)MemberOctober 25, 2006 at 3:01 pmPost 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.
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”;
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)User (Old forums)MemberOctober 25, 2006 at 5:07 pmPost count: 23064
Yes, the problem that I am facing is the number of rows. I was able to find the DataRow Title which includes the number of rows underneath a group in this block of code. But I am wondering how I can do this for the GroupKeys:
private void dataViewGrid_GroupingUpdated(object sender, EventArgs e)
Xceed.Grid.GridControl grid = sender as Xceed.Grid.GridControl;
if (grid.Groups.Count > 0)
GroupManagerRow row = (GroupManagerRow)grid.Groups.AmbientParent.GridControl.CurrentRow;
string title = row.Title;
int start = title.IndexOf(“-“)+1;
int length =title.IndexOf(“item”) – start;
string count = title.Substring(start, length).Trim();
The problem that I am facing is that because the user is dynamically creating the groups by dragging and dropping the columns to the column manager in the default datagridview I can’t seem to readily access the datarows for any group.
Is there any apparent way that I could access that DataRows attribute through the GroupManagerRow?
Imported from legacy forums. Posted by TParker (had 348 views)User (Old forums)MemberOctober 26, 2006 at 2:46 pmPost count: 23064
You cannot change the groups key once it is set, thus you will not be able to change the way it sorts. The only workaround we see is to group twice. That is, you let the grid group the first time, you get the information on the number of rows in each group, then delete the grouping, and do it a second time, but this time, use the QueryGroupKeys event to set the right keys so the groups will sort in the right order. Of course, this will work ok if you have a small grid, but as the number of rows increases, this may become a poor workaround.
BTW, you should retrieve the GroupManagerRow this way :
GroupManagerRow row = ( GroupManagerRow )gridControl1.Groups[ 0 ].HeaderRows[ 0 ];
Imported from legacy forums. Posted by André (had 4034 views)
- You must be logged in to reply to this topic.