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
100
WinGrid Grouping multiple columns in code
posted

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.