Articles in this section
Category / Section

How to filter the more than one field with specified criteria in WinForms GridGroupingControl?

2 mins read

Filtering


As per the filtering architecture, the filtering is performed based on the previous result of the filtering. In order to filter more than one fields, the expression can be added to RecordFilterDescriptorCollection instead of using the FilterCondition. In this example, this expression will filter the columns that are not all equal to the value 4.


C#

private void btnFilter_Click(object sender, EventArgs e)
{
   Filter();
}
 
public void Filter()
{
   this.gridGroupingControl1.TableDescriptor.RecordFilters.Clear();
   string Expression = string.Empty;
   if (checkBox1.Checked)
   {
      Expression = "[Col1] <> 4";
   }
   if (checkBox2.Checked)
   {
      if (checkBox1.Checked)
      {
         Expression += "OR [Col2] <> 4";
      }
      else
      {
         Expression = "[Col2]<>4";
      }
   }
   if (checkBox3.Checked)
   {
      Expression = "[Col3] <> 4";
      if (checkBox1.Checked)
      {
         Expression += "OR [Col1] <> 4";
      }
      if (checkBox2.Checked)
      {
         Expression += "OR [Col2] <> 4";
      }
   }
   this.gridGroupingControl1.TableDescriptor.RecordFilters.Add(Expression);
}

VB

Private Sub btnFilter_Click(ByVal sender As Object, ByVal e As EventArgs)
   Filter()
End Sub
 
Public Sub Filter()
    Me.gridGroupingControl1.TableDescriptor.RecordFilters.Clear()
    Dim Expression As String = String.Empty
    If checkBox1.Checked Then
        Expression = "[Col1] <> 4"
    End If
    If checkBox2.Checked Then
        If checkBox1.Checked Then
          Expression &= "OR [Col2] <> 4"
       Else
          Expression = "[Col2]<>4"
       End If
    End If
    If checkBox3.Checked Then
       Expression = "[Col3] <> 4"
       If checkBox1.Checked Then
          Expression &= "OR [Col1] <> 4"
       End If
       If checkBox2.Checked Then
          Expression &= "OR [Col2] <> 4"
       End If
    End If
    Me.gridGroupingControl1.TableDescriptor.RecordFilters.Add(Expression)
End Sub

The screenshots below displays the filtering of more than one field in GridGroupingControl.

Show filter more than one fields


Show filter more than one fields while choosing specific columns

Samples:

C#: Filter more than one fields_CS

VB: Filter more than one fields_VB

 

Reference Link: Filtering

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