Hi,
I have filtering on a grid set to AllRowsInBand. When I filter the child rows I would like to hide any parent rows that have no children due to the filter being applied. I've tried doing the following in FilterRow but it doesn't have the desired effect.
if (e.Row.HasParent()) //child row { if (e.Row.ParentRow.ChildBands[0].Rows.FilteredInRowCount == 0) // Visible Children e.Row.ParentRow.Hidden = true; }
Can anyone help with this?
Regards,
Martin
Hi Martin,
Is the code that sets the hidden property ever getting hit?
Even if it is, the code you have here is probably not a good idea. Filtering is performed asynchronously. So getting the FilteredInRowCount while you are in the middle of a filter operation is, at the very least, unreliable.
Try using InitializeRow instead and see if that works.
if (e.Row.ChildBands[0].FilteredinRowCount == 0)
e.Row.Hidden = true;
else
e.Row.Hidden = false;
Of course you would only do this for the parent rows, so check the row.Band.Key first.
If that still doesn't work, then the only thing I can think of is to make the filtering synchronous. This means that the UI will be locked while the filtering is in progress, but it's the only way to ensure that the filtering is complete before you determine whether the parent row should be hidden.
To make Filtering synchronous, you handle the BeforeRowFilterChanged event and set e.ProcessMode to Synchronous (or maybe SynchronousExpanded in your case).
Hi Mike,
Thanks for that. Yes the hidden property is being set but it is unreliable as you said. I've tried the InitializeRow method but this only seems to fire when the grid is first loaded. I need to hide parents with no children everytime a filter is applied. Also need to be able to display hidden parents once filters are cleared. Have you any other suggestions?
Hm. InitializeRow fires whenever a value in a cell changes, in addition to firing when the row is created. But I guess it does not fire when the filtering is changed. That kinda makes sense, so no cell value has changed in the filtered rows.
You can force the event to fire, though.
private void ultraGrid1_AfterRowFilterChanged(object sender, Infragistics.Win.UltraWinGrid.AfterRowFilterChangedEventArgs e) { this.ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.FireInitializeRow); } private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { if (e.Row.Band.Index == 0) { e.Row.Hidden = (e.Row.ChildBands[0].Rows.FilteredInRowCount == 0); } }
This worked okay for me in a relatively small grid with 26 rows. I'm not sure if this will work as well in a very large grid with a lot of rows - you might run into problems with the asynchronous nature of the filtering, but then again you might not.
If this is not working for you reliably, then I think the only solution would be to make the filtering synchronous.
private void ultraGrid1_BeforeRowFilterChanged(object sender, Infragistics.Win.UltraWinGrid.BeforeRowFilterChangedEventArgs e) { e.ProcessMode = Infragistics.Win.UltraWinGrid.ProcessMode.SynchronousExpanded; }
That worked a treat. The grid in my app has over a hundred parent rows each with two or more children and the response is very good in async mode.
I was wondering if this was something that could be added to the grid as a feature. I assume it would be much easier to hide parents with empty children in the filtering code than it is to do so after the fact?
Anyway - thanks for the help it's much appreciated.
manopt_martin said:I was wondering if this was something that could be added to the grid as a feature.
You should Submit a feature request to Infragistics
manopt_martin said:I assume it would be much easier to hide parents with empty children in the filtering code than it is to do so after the fact?
No, I don't think it would be any easier. Either way, you have to loop through all of the parent and all of the child rows.