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
2325
adding custom description to groupby, but grouping by multiple columns
posted

I understand that I can set a custom group by description in the InitializeGroupByRow event. This works fine if I have 1 column I am grouping by.  However in my case I have 3 columns I am grouping by.   I have tried the following so far (trying just to get at least one description working....)

var rowId = e.Row.Column.Key;
UltraGridRow row;
switch (rowId)
{
    case "FunctionalAreaNumber" :
        e.Row.Appearance.BackColor = Color.LightSteelBlue;
        row = e.Row.GetChild(ChildRow.First);
        if (row != null)
        {
            if (e.Row.ChildBands.FirstRow.Cells != null)
            {
                e.Row.Description = string.Format("Functional Area: {0}",
                    e.Row.ChildBands.FirstRow.Cells["FunctionalAreaDescription"].Value);
            }
        }
        break;
    case "SubsystemNumber" :
        e.Row.Appearance.BackColor = Color.LightBlue;
        break;
    case "ModuleNumber" :
        e.Row.Appearance.BackColor = Color.Aqua;
        break;
}:

However this doesnt appear to work as Cells seem to always be null so I cant get the description from the functional area description column.  Any suggestions would be appreciated on how to resolve this.

Thanks!

  • 2165
    Verified Answer
    posted

    Hello Jeff,

    Thank you for the provided code snipped.

    When you group by some columns the InitializeGroupByRow is fired in order to initialize the layout of the grid. So, in your case first are initialized the rows for  the "FunctionalAreaNumber" column. At that moment the first row of the child band is not yet grouped by and its value is not null. After that the rows from the second column start to initialize but as the first group of rows is already initialized the first row of the child band is grouped and thus its value is null. That’s why your description is not changed. So what I could suggest you it to use recursion in order to get to a level of the row where the first row of the child band is not yet grouped by and take the value you need. To be more clear I’ve implemented this suggestion in a simple sample , and you could run and evaluate it, please see attached zip.

    I hope that this will help you.

    Please do not hesitate to contact me if you have any further question.

    GroupByMultipleColumns.zip