Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter Observable Collection Class Collection

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.

like image 919
DATT OZA Avatar asked Feb 20 '10 19:02

DATT OZA


People also ask

How do I filter in C#?

C# filter list with iteration. In the first example, we use a foreach loop to filter a list. var words = new List<string> { "sky", "rock", "forest", "new", "falcon", "jewelry" }; var filtered = new List<string>(); foreach (var word in words) { if (word. Length == 3) { filtered.

What is difference between observable collection and list?

The true difference is rather straightforward:ObservableCollection implements INotifyCollectionChanged which provides notification when the collection is changed (you guessed ^^) It allows the binding engine to update the UI when the ObservableCollection is updated. However, BindingList implements IBindingList.

What are observable collections?

An ObservableCollection is a dynamic collection of objects of a given type. Objects can be added, removed or be updated with an automatic notification of actions. When an object is added to or removed from an observable collection, the UI is automatically updated.


1 Answers

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

like image 183
Jobi Joy Avatar answered Oct 25 '22 06:10

Jobi Joy