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) - 0Detail - 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
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.
Mike - I'm doing something similar and you're correct about the sort, it's necessary to re-apply the RowSpacingAfter to the last row.
For the benefit of others (and there may be a better way)...
private void ultraGrid_AfterSortChange(object sender, BandEventArgs e)
{
if (e.Band.Key == "myChildBand")
System.Collections.
row.RowSpacingAfter = -1;
if (row.HasNextSibling(false, true) == false)
row.RowSpacingAfter = 20;
}