title: Apply multiple Filtering to WPF datagrid using C#
body: <p>I have a datagrid which is boud to a database table. I could filter the datagrid using an ICollectionView using the code below: </p>
  
  <pre><code>            lstOrdsRlsd = new ObservableCollection&lt;OrdsRlsd&gt;(GV.dbContext.OrdsRlsds);
              view = CollectionViewSource.GetDefaultView(lstOrdsRlsd);
  
              if (lstOrdsRlsd.Count &gt; 0)
              {
                  dgRecords1.ItemsSource = view;                  
              }
  
  
  
    private void FilterRecords(string FieldName, string Condition, object Value1, object Value2)
      {
          OrdsRlsd vitem;
          switch (FieldName)
          {
              case "OrderNo":
  
                  view.Filter = item =&gt;
                  {
                      vitem = item as OrdsRlsd;
                      switch (Condition)
                      {
                          case "=":
                              if (vitem.OrderNo == Convert.ToDouble(Value1))
                                  return true;
                              break;
                          case "&gt;=":
                              if (vitem.OrderNo &gt;= Convert.ToDouble(Value1))
                                  return true;
                              break;
                          case "&lt;=":
                              if (vitem.OrderNo &lt;= Convert.ToDouble(Value1))
                                  return true;
                              break;
                          case "between":
                              if (vitem.OrderNo &gt;= Convert.ToDouble(Value1) &amp;&amp; vitem.OrderNo &lt;= Convert.ToDouble(Value2))
                                  return true;
                              break;
                      }
  
                      return false;
                  };
                  break;
  
              case "DateRqd1":
  
                  view.Filter = item =&gt;
                  {
                      vitem = item as OrdsRlsd;
                      switch (Condition)
                      {
                          case "=":
                              if (vitem.DateRqd1 == Convert.ToDateTime(Value1))
                                  return true;
                              break;
                          case "&gt;=":
                              if (vitem.DateRqd1 &gt;= Convert.ToDateTime(Value1))
                                  return true;
                              break;
                          case "&lt;=":
                              if (vitem.DateRqd1 &lt;= Convert.ToDateTime(Value1))
                                  return true;
                              break;
                          case "between":
                              if (vitem.DateRqd1 &gt;= Convert.ToDateTime(Value1) &amp;&amp; vitem.DateRqd1 &lt;= Convert.ToDateTime(Value2))
                                  return true;
                              break;
  
                      }
                      return false;
                  };
                  break;
  </code></pre>
  
  <p>}</p>
  
  <p>It works for me when there is only one filtering condition. But when i apply multiple conditions the datagrid filters by the last condition. This is the code executed when the user clicks the filter button.</p>
  
  <pre><code>   private void BtnFilter_Click(object sender, RoutedEventArgs e)
      {
          foreach (var rec in lstClsFilterGrid)
          {
              FilterRecords(rec.FieldName, rec.Condition, rec.Value1, rec.Value2);
          }
  
      }
  </code></pre>
  
  <p>where lstClsFilterGrid is a llist of class objects with the filter conditions. </p>
  
  <p>I am attaching a screenshot of my form.<img src="https://i.stack.imgur.com/ssmhV.png" alt="enter image description here"></p>