Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6606887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:26:37+00:00 2026-05-25T19:26:37+00:00

I have a datagrid which is boud to a database table. I could filter

  • 0

I have a datagrid which is boud to a database table. I could filter the datagrid using an ICollectionView using the code below:

            lstOrdsRlsd = new ObservableCollection<OrdsRlsd>(GV.dbContext.OrdsRlsds);
            view = CollectionViewSource.GetDefaultView(lstOrdsRlsd);

            if (lstOrdsRlsd.Count > 0)
            {
                dgRecords1.ItemsSource = view;                  
            }



  private void FilterRecords(string FieldName, string Condition, object Value1, object Value2)
    {
        OrdsRlsd vitem;
        switch (FieldName)
        {
            case "OrderNo":

                view.Filter = item =>
                {
                    vitem = item as OrdsRlsd;
                    switch (Condition)
                    {
                        case "=":
                            if (vitem.OrderNo == Convert.ToDouble(Value1))
                                return true;
                            break;
                        case ">=":
                            if (vitem.OrderNo >= Convert.ToDouble(Value1))
                                return true;
                            break;
                        case "<=":
                            if (vitem.OrderNo <= Convert.ToDouble(Value1))
                                return true;
                            break;
                        case "between":
                            if (vitem.OrderNo >= Convert.ToDouble(Value1) && vitem.OrderNo <= Convert.ToDouble(Value2))
                                return true;
                            break;
                    }

                    return false;
                };
                break;

            case "DateRqd1":

                view.Filter = item =>
                {
                    vitem = item as OrdsRlsd;
                    switch (Condition)
                    {
                        case "=":
                            if (vitem.DateRqd1 == Convert.ToDateTime(Value1))
                                return true;
                            break;
                        case ">=":
                            if (vitem.DateRqd1 >= Convert.ToDateTime(Value1))
                                return true;
                            break;
                        case "<=":
                            if (vitem.DateRqd1 <= Convert.ToDateTime(Value1))
                                return true;
                            break;
                        case "between":
                            if (vitem.DateRqd1 >= Convert.ToDateTime(Value1) && vitem.DateRqd1 <= Convert.ToDateTime(Value2))
                                return true;
                            break;

                    }
                    return false;
                };
                break;

}

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.

   private void BtnFilter_Click(object sender, RoutedEventArgs e)
    {
        foreach (var rec in lstClsFilterGrid)
        {
            FilterRecords(rec.FieldName, rec.Condition, rec.Value1, rec.Value2);
        }

    }

where lstClsFilterGrid is a llist of class objects with the filter conditions.

I am attaching a screenshot of my form.enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:26:37+00:00Added an answer on May 25, 2026 at 7:26 pm

    So the workflow on this form is, User creates a condition to filter on and can optionally filter the collection or add another condition, is that correct?

    If so, then you will have to be able to pass a collection of conditions (probably to an overloaded filter method).

    I have previously filtered on multiple (fixed) conditions (i.e. several checkboxes bound to properties that map to pre-arranged conditions, say “Past 30 days”, “Completed Orders”, “Overdue Shipments”, etc.).

    My filter would check the items based on all of those properties. In your case, you have an indeterminate number of dynamic conditions.

    If this were me, I would have a list to which I would add conditions, then pass the whole collection into a filtering method then each object would have to satisfy all of the conditions in a for loop to return true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagrid which is bound to a database table. I need to
I have a datagrid view which shows table data from a database Environment: -
I have a DataGrid which is being bound dynamically to a database query. The
I have a DataGrid which i am using on the page alogn with 4
I am using asp.net 2.0 and c#. I have a datagrid in which I
I have a Silverlight 4 DataGrid which has its ItemsSource bound to an ObservableCollection
I have Datagrid which is bound to my Database <WpfToolkit:DataGrid Name=DataGrid1 Grid.Row=1 ItemsSource={Binding Path=MainSearchBinding}
I have a datagrid which I am using LINQ to fill, I then add
I have a WPF DataGrid which is populated from a database. There is a
I have a datagrid which is bound to a table. I have a field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.