ComponentOne Basic Library for UWP
Basic Library Overview / CollectionView for UWP / Getting Started with C1CollectionView / Filtering C1CollectionView
In This Topic
    Filtering C1CollectionView
    In This Topic

    With C1CollectionView you can filter a collection to produce a new sub-set containing exactly those elements of the original collection for which a given predicate returns true. When you filter a C1CollectionView, the underlying data set is not affected. The Filter property gets or sets a callback used to determine if an item is suitable for inclusion in the view.

    For example, you can set a predicate to the Filter property and this will cause the list to be filtered by that predicate.

    Visual Basic
    Copy Code
    ' create an observable list of customers
    Dim list = New System.Collections.ObjectModel.ObservableCollection(Of Customer)()
    
    ' create a C1CollectionView from the list
    _view = New C1.Xaml.C1CollectionView(list)
    
    ' filter by country = Austria. Customers not from Austria will be filtered out.
    _view.Filter = Sub(item As Object)
    Dim c As Customer = TryCast(item, Customer)
    If c IsNot Nothing Then
          If c.Country.Equals("Austria") Then
                Return True
          End If
    End If
    Return False
    End Sub
    

    C#
    Copy Code
    // create an observable list of customers
    var list = new System.Collections.ObjectModel.ObservableCollection<Customer>();
    
    // create a C1CollectionView from the list
    _view = new C1.Xaml.C1CollectionView(list);
    
    // filter by country = Austria. Customers not from Austria will be filtered out.
    _view.Filter = delegate(object item)
    {
        Customer c = item as Customer;
        if (c != null)
        {
            if (c.Country.Equals("Austria"))
                return true;
        }
        return false;
    };
    
    Note: If the collection implements INotifyCollectionChanged any changes to the data will be applied to the filter even after it’s been set.

    For an advanced example of filtering, see the Filter sample for FlexGrid for UWP: https://developer.mescius.com/samples.

    See Also