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
75
Interband Spacing Question
posted

We have a simple Header-Detail grid (ie 2 Bands) and want to furthur visually separate each Header group in the grid.  When we increase the Interband Spacing property, it also increases the spacing between the related Header and Detail records.  However, we're looking for something like the following:

Header-Detail Spacing (ie spacing b/w Bands 0 and 1)    - 0
Detail - Header Spacing (ie spacing b/w Bands 1 and 0)  - 5

Is it possible to assign different spacing for the two bands?

Thanks in advance

  • 469350
    Verified Answer
    Offline posted

    Hi,

    So you mean if you have a parent row in Band 0, you want there to be no space between that row and it's first child row.

    But you want there to be a space between the last child row in an island and the next parent row?

    If that's the case, then you can't do it with InterbandSpacing. But you might be able to achieve what you want using RowSpacingAfter.

    The basic approach would look something like this:


            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                e.Layout.InterBandSpacing = 0;
            }

            private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
            {
                e.Row.RowSpacingAfter = 0;
                if (e.Row.Band.Index != 0)
                {
                    if (e.Row.HasNextSibling(false, true) == false)
                    {
                        e.Row.RowSpacingAfter = 5;
                    }
                }
            }

    The problem with this is that InitializeRow won't necessarily fire all the times you will need it to. The event fires if you add a new row to the grid, for example, but it only fires for the new row, it will not re-fire for existing rows, so those rows might end up showing spaces that you would want to clear.

    Another example of a case like this is sorting. If you sort the child rows, the InitializeRow event will not fire for each row again, since it doesn't need to. So the spacing would end up after the wrong row. 

    This is easy enough to deal with. You just refresh the rows collection when something changes. So, for example, to handle the sorting case, you could do this:


            private void ultraGrid1_AfterSortChange(object sender, Infragistics.Win.UltraWinGrid.BandEventArgs e)
            {
                UltraGrid grid = (UltraGrid)sender;
                grid.Rows.Refresh(RefreshRow.FireInitializeRow, true);
            }

    This forces the InitialieRow to re-fire after the grid is sorted.

    There are several caveats to this, though.

    • If you have a lot of rows in the grid, refreshing them could become an expensive operation and may affect performance. 
    • Some operations on the grid are performed asynchronously, such as filtering. So if you do the same thing in the AfterFilterRowFilterChanged and then filter the grid, I'm not entirely sure it will work. You might have to force the filtering to by done synchronously, which again might affect performance.
    • It's not neccessarily obvious where you need to refresh the rows. Sorting and Filtering are two pretty obvious cases. Another one would be AfterRowInsert and AfterRowsDeleted. There may be others, though, and I can't say for sure what all of them are. So you might want to do some testing to make sure nothing gets out of synch.