Category / Section
How to hide a row based on cellvalue in WinForms GridGroupingControl?
1 min read
Hide a row
In order to hide a particular row based on the Cellvalue, QueryRowHeight can be used. Please refer to the below code snippet. The record can be gained by using from the DisplayElement collection. Then the record’s value can be cached from GetValue method.
The matched search text of the record can be set to zero using the Size property to hide the record.
C#
void TableModel_QueryRowHeight(object sender, GridRowColSizeEventArgs e) { if (e.Index >= gridGroupingControl1.TableControl.TopRowIndex) { if (gridGroupingControl1.Table.DisplayElements[e.Index] != null) { Element el = gridGroupingControl1.Table.DisplayElements[e.Index]; Record rec = el.GetRecord(); if (el.Kind == DisplayElementKind.Record && rec != null && rec.GetValue("FirstName").Equals("Mary"))//colindex and the respective text. { e.Size = 0; e.Handled = true; } } } }
VB
Private Sub TableModel_QueryRowHeight(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs) If e.Index >= gridGroupingControl1.TableControl.TopRowIndex Then If gridGroupingControl1.Table.DisplayElements(e.Index) IsNot Nothing Then Dim el As Element = gridGroupingControl1.Table.DisplayElements(e.Index) Dim rec As Record = el.GetRecord() If el.Kind = DisplayElementKind.Record AndAlso rec IsNot Nothing AndAlso rec.GetValue("City").Equals("London") Then'colindex and the respective text. e.Size = 0 e.Handled = True End If End If End If End Sub
Screenshot
Before
After
Samples:
C#: HideRow_CS
VB: HideRow_VB