9

I have implemented Linq-To-Sql.. Add necessary table in it... after that linq class will automatically set property for field.. I implemented one class using ObservableCollection class.. and pass datacontextclass object in its constructor...

so after getting all data how to filter it?

  public class BindBookIssueDetails : ObservableCollection
        {
            public BindBookIssueDetails(DataClasses1DataContext dataDC)
            {
                foreach (Resource_Allocation_View res in dataDC.Resource_Allocation_Views)
                {
                    this.Add(res);
                }
            }
        }

private BindBookIssueDetails bResource;
bResource = new BindBookIssueDetails(db);
_cmbResource.ItemSource=bResource;

Please Help me.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
DATT OZA
  • 1,321
  • 3
  • 13
  • 14

2 Answers2

13

You can use CollectionViewSource and filter it. So that it affect only at the View(.XAML) side

    ICollectionView collectionView = CollectionViewSource.GetDefaultView(bResource);
    collectionView.Filter = new Predicate<object>(YourFilterFunction);

Check out this blog for more details. http://bea.stollnitz.com/blog/?p=31

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Jobi Joy
  • 49,102
  • 20
  • 108
  • 119
0

I tried to use @Jobi's solution but for some reason I got an exception trying to fire FilterFunction.

So I used a slightly different approach. I cast CollectionViewSource's DefaultView to a BindingListCollectionView

myVS=(BindingListCollectionView)CollectionViewSource.GetDefaultView(sourceofdata);

and now I can construct an SQL-like filter string and apply it like that:

myVS.CustomFilter=myfilterstring;

I will still try to resolve my problem (I presume @Jobi's solution is more flexible).