Articles in this section
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

Before hide a row in GridGroupingControl

 

After

After hide a row in GridGroupingControl

Samples:

C#: HideRow_CS

VB: HideRow_VB

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied