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

    Group your collection by a particular property using the GroupDescriptions property on C1CollectionView.

    For example, to group the collection by the "Country" property:

    Visual Basic
    Copy Code
    Dim list = New System.Collections.ObjectModel.ObservableCollection(Of Customer)() 
    ' create a C1CollectionView from the list
    _view = New C1.Xaml.C1CollectionView(list)
    
    ' group customers by country
    _view.GroupDescriptions.Add(New C1.Xaml.PropertyGroupDescription("Country"))        
    

    C#
    Copy Code
    var list = new System.Collections.ObjectModel.ObservableCollection<Customer>();
    
    // create a C1CollectionView from the list
    _view = new C1.Xaml.C1CollectionView(list);
    
    // group customers by country
    _view.GroupDescriptions.Add(new C1.Xaml.PropertyGroupDescription("Country"));
    
    Note: If the collection implements INotifyCollectionChanged any changes to the data will be applied to the grouping even after it’s been set.

    The C1FlexGrid control supports grouping on C1CollectionView for you. If you are grouping with any other control you will need to define a GroupStyle to control the appearance of each group.

    For example, here is a GroupStyle defined for a standard ListBox control:

    Markup
    Copy Code
    <ListBox
        Name="_listBox"
        ItemsSource="{Binding Customers}">
        <ListBox.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" />
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ListBox.GroupStyle>
    </ListBox>
    
         
    See Also