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
310
Setting background of child rows after a column sort
posted

First just a short thanks to all who have posted here, I have solved many a problem with all the great solutions provided.

Today, I have a grid with hierarchiel data that has child rows. I want the child rows to be the same background as the parent row. I found how to do this initially with the initialize row event. It looks like this and works just fine:

            if (e.Row.ParentRow != null)
            {
                e.Row.Appearance.BackColor = e.Row.ParentRow.IsAlternate
                    ? e.Row.ParentRow.Band.Override.RowAlternateAppearance.BackColor
                    : e.Row.ParentRow.Band.Override.RowAppearance.BackColor;
            }

But if I now sort the grid based on a column, the child rows no longer maintain the backcolor. I thought to make a method that implements similar logic (see below). But running it after the sorting operation, it does not work as expected with many children mis-colored from their parent.

        private void SetChildRowBackground()
        {
            foreach (var row in grid.Rows)
                if( row.HasChild() )
                    foreach( UltraGridChildBand child in row.ChildBands)
                        foreach( var childRow in child.Rows)
                            childRow.Appearance.BackColor = row.IsAlternate
                                 ? childRow.ParentRow.Band.Override.RowAlternateAppearance.BackColor
                                 : childRow.ParentRow.Band.Override.RowAppearance.BackColor;
        }

Is their a more appropriate approach?

Kent

Parents Reply Children
No Data