We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to compare date columns using expression in WinForms GridControl?

Platform: WinForms |
Control: GridControl

Compare the date columns using expressions

To compare the date columns using expressions, can be handled by `SelectedIndexChanged` event.

1. FilterCompareOperator helps to give the comparer condition to filter the records.

2. RecordFilterDescriptor provides the filter criteria by displaying only a subset of records from the underlying data source.


private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    string s = "";
    switch (comboBox1.SelectedIndex)
        case 0:  //dates >= April 17, 2008
            s = string.Format("[{0}]GreaterThanOrEqualTo {{{1}}}", "date", "4/17/2008");
            FilterCondition con = new FilterCondition(FilterCompareOperator.GreaterThanOrEqualTo, "4/17/2008");
            RecordFilterDescriptor rec = new RecordFilterDescriptor("date", con);
        case 1: //dates < April 16, 2008
            s = string.Format("[{0}] LessThan {{{1}}}", "date", "4/16/2008");
            FilterCondition con1 = new FilterCondition(FilterCompareOperator.LessThan, "4/16/2008");
            RecordFilterDescriptor rec1 = new RecordFilterDescriptor("date", con1);
        case 2: //dates < April 19, 2008
            s = string.Format("[{0}] GreaterThan {{{1}}}", "date", "4/19/2008"); //first arg empty means DateTime.MinValue
            FilterCondition con2 = new FilterCondition(FilterCompareOperator.GreaterThan, "4/19/2008");
            RecordFilterDescriptor rec2 = new RecordFilterDescriptor("date", con2);
     this.label2.Text = s;//so you can see the actual filter



Private Sub comboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles comboBox1.SelectedIndexChanged
 Dim s As String = ""
 Select Case comboBox1.SelectedIndex
  Case 0 'dates >= April 17, 2008
   s = String.Format("[{0}]GreaterThanOrEqualTo {{{1}}}", "date", "4/17/2008")
   Dim con As New FilterCondition(FilterCompareOperator.GreaterThanOrEqualTo, "4/17/2008")
   Dim rec As New RecordFilterDescriptor("date", con)
  Case 1 'dates < April 16, 2008
   s = String.Format("[{0}] LessThan {{{1}}}", "date", "4/16/2008")
   Dim con1 As New FilterCondition(FilterCompareOperator.LessThan, "4/16/2008")
   Dim rec1 As New RecordFilterDescriptor("date", con1)
  Case 2 'dates < April 19, 2008
   s = String.Format("[{0}] GreaterThan {{{1}}}", "date", "4/19/2008") 'first arg empty means DateTime.MinValue
   Dim con2 As New FilterCondition(FilterCompareOperator.GreaterThan, "4/19/2008")
   Dim rec2 As New RecordFilterDescriptor("date", con2)
  Case Else
 End Select
 Me.label2.Text = s 'so you can see the actual filter
End Sub


Compare the date column in gridcontrol

Compare the date column in gridcontrol

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile