I have a set of columns and I want to group by multiple columns. For example, lets say i have the following columns:
Name|Age|School|Grade
I want to be able to group by Name and Age so I can see all the schools and grades for a particular name and age, or group by School and Grade and see all of the names and ages in that school/grade. (Note: I want this only to be a hierarchy/tree like, as in I dont want it to be grouped by school, then have a list of grades underneath which has a list of names/ages)
The only way I can determine to do this is to create another column for each grouping that concatenates the Name+Age or School+Grade and then group by that. Is there another way that I am missing?
The real problem though is, I want to be able to do this based on a radio button selection to pick the grouping type. How do you add groupby columns in code? I saw you can do this in the InitializeLayout event, as shown below, but how do you force the grid to initialize the layout again after the grid is already displayed, or is there another method of adding sorting columns that is easier?
private void gridName_InitializeLayout(object sender, InitializeLayoutEventArgs e){ e.Layout.Bands[0].SortedColumns.Add("ColumnKey", false, true);}
Thank you ahead of time for any help.
mirage456 said:The only way I can determine to do this is to create another column for each grouping that concatenates the Name+Age or School+Grade and then group by that. Is there another way that I am missing?
Creating a hidden column will work. Another option is to use a custom GroupByEvaluator for the column. In a case like this where you want to group by 2 columns, you would probably also have to use a custom SortComparer on the column. Using a hidden column is probably easier and requires less code.
mirage456 said:The real problem though is, I want to be able to do this based on a radio button selection to pick the grouping type. How do you add groupby columns in code? I saw you can do this in the InitializeLayout event, as shown below, but how do you force the grid to initialize the layout again after the grid is already displayed, or is there another method of adding sorting columns that is easier? private void gridName_InitializeLayout(object sender, InitializeLayoutEventArgs e){ e.Layout.Bands[0].SortedColumns.Add("ColumnKey", false, true);}
You can do the same thing outside the InitializeLayout event. Just use grid.DisplayLayout instead of e.Layout.
Hi ,
The only way I can determine to do this is to create another column for each grouping that concatenates the Name+Age or School+Grade and then group by that.
hope this is the best approach you can go ahead...
The real problem though is, I want to be able to do this based on a radio button selection to pick the grouping type. How do you add groupby columns in code? I saw you can do this in the InitializeLayout event,
Sure you can very do this anywhere after the grid is initialized with the specific column you group,be sure to clear the existing grouping and then group it
try these two line code in the radio button event
UltraGrid1.DisplayLayout.Bands(0).SortedColumns.Clear()
UltraGrid1.DisplayLayout.Bands(0).SortedColumns.Add("GroupColName", False, True)
Hppy Koding,
Arun