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
895
Add space after each group, but not after the header columns.
posted

I have a grid with the GroupBy feature turned on.

I'd like to add some space between the groups that look like this...

However, I always seem to end up with some space between the header and the first group

Or I end up with space between the groups and the rows in that group.

I was trying to use...

GroupByRowSpacingBefore and GroupByRowSpacingAfter

Are there other settings I should consider trying?

Thanks,

Brian.

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi Brian,

    Hm, this will be a bit tricky. If you use GroupByRowSpacingBefore, then there will be a space before each group, which means a space between the headers and the first visible GroupByRow.

    GroupByRowSpacingAfter won't work, because that will create space between the GroupByRow and it's child rows. 

    It seems like what you really want is a space after the last data row in each group. Or a space before each GroupByRow except the first one.

    It looks like you must be setting the HeaderPlacement to get the headers to appear only once at the top, too. Or possibly you are setting ViewStyle to SingleBand, which would have the same effect. If you don't do this, then the headers will appear under each GroupByRow and then using GroupByRowSpacingBefore would not be a problem.

    So in order to make this work, you would have to dynamically change the spacing before the row based on whether the GroupByRow is the first visible row or not. The obvious way to acheive this would be to handle the Before or AfterRowRegionScroll event and set the RowSpacingBefore on each GroupByRow. But this is a bad idea, because you will essentially be changing the scroll metrics during a scroll operation and that's going to cause problems.

    I was able to get this to work like this:

    UltraGridGroupByRow lastAdjustGroupbyRow = null;
            private void ultraGrid1_AfterRowRegionScroll(object sender, RowScrollRegionEventArgs e)
            {
                this.AdjustGroupByRowSpacing(e.RowScrollRegion);
            }       


            private void AdjustGroupByRowSpacing(RowScrollRegion rowScrollRegion)
            {
                this.ultraGrid1.BeginUpdate();
                try
                {
                    if (lastAdjustGroupbyRow != null)
                        lastAdjustGroupbyRow.RowSpacingBefore = -1;

                    foreach (VisibleRow visibleRow in rowScrollRegion.VisibleRows)
                    {
                        UltraGridGroupByRow groupByRow = visibleRow.Row as UltraGridGroupByRow;
                        if (groupByRow != null)
                        {
                            if (rowScrollRegion.VisibleRows.IndexOf(visibleRow) == 0)
                            {
                                groupByRow.RowSpacingBefore = 0;
                                this.lastAdjustGroupbyRow = groupByRow;
                            }
                        }
                    }
                }
                finally
                {
                    this.ultraGrid1.EndUpdate();
                }
            }

     

    But this code is not great, because there's a nasty flicker every time you scroll the grid vertically. Also, you have to call something like this in the Form_Load or at some point after the grid is bound:

    this.AdjustGroupByRowSpacing(this.ultraGrid1.DisplayLayout.RowScrollRegions[0]);

    Anyway, like I said, this is probably not a good idea since it changes the scroll metrics while in the middle of a scroll operation. There may be other side effects in addition to the flicker. So if the spacing is that important to you, I'd recommend putting the headers under each group.

Children