ComponentOne CollectionView
Work with CollectionView / Grouping
In This Topic
    Grouping
    In This Topic

    CollectionView implements the ICollectionView interface to support grouping, which enables you to group data using the GroupAsync method of the C1CollectionView class. This method calls the grouping operation in the collection view and groups data according to the specified field names, group path, or group descriptions. When grouping is applied, it automatically sorts the data and splits it into groups by combining rows based on column values.

    The following image shows how the customer names are grouped by country in a ListView.

    grouping

    The following code implements grouping in ListView using the GroupAsync method. In this example, name of the customers is grouped by country in the ListView control.

    Private cv As C1CollectionView(Of Customer)
    
    Public Sub New()
        InitializeComponent()
        cv = New C1CollectionView(Of Customer)(Customer.GetCustomerList(100))
        ListView1.SetItemsSource(cv, "Name")
        ListView1.Visible = True
    End Sub
    Private Sub btnGroup_Click(sender As Object, e As EventArgs) Handles btnGroup.Click
        ListView1.SetItemsSource(cv, "Name", "City")
        cv.GroupAsync(Function(v) v.Customer)
    End Sub
    
    C1CollectionView<Customer> cv;
    public Grouping()
    {
        InitializeComponent();
    
        cv = new C1CollectionView<Customer>(Customer.GetCustomerList(100));
        listView1.SetItemsSource(cv, "Name");
        listView1.Visible = true;
    }
    
    private void btnGroup_Click(object sender, EventArgs e)
    {
        listView1.SetItemsSource(cv, "Name", "City");
        cv.GroupAsync(v => v.Country);
    }