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.

Parents
No Data
Reply
  • 75
    posted

     Hi I am currently doing something simila. Basically I need to group by multiple columns since one of them has multiple fields example:

     

    column1 column2 column3

      bla           test          1

      bla           test           2

      bla           test           3

     

     

    what i need is that it groups column1 and column2 so that it expands to show what there is in column3.

     

    I tried to use to code suggested in this post but the grid stays in flat style and shows data as the example above, is there any other code i need to type in for this to work? Oh yeah I am currenty using version 7.1 don't know if it supports this functionality

Children