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

    CollectionView implements the ICollectionView interface to support sorting data in ascending and descending order. It enables you to sort data according to the specified sort path and direction using SortAsync method of the C1CollectionView class. CollectionView also allows you to set the direction of sort operation using Direction property of the SortDescription class which accepts values from the SortDirection enumeration. Moreover, it allows you to specify the path of a data item to which the sort operation needs to be applied using the SortPath property.

    The following GIF displays how the sorting is implemented using the SortAsync method.

    sorting

    The following code demonstrates the implementation of the SortAsync method to sort data in DataGridView. In this example, Name column of DataGridView is sorted alphabetically in ascending order. This example uses the sample created in the Quick Start section.

    Private Async Sub btnSort_Click(sender As Object, e As EventArgs) Handles btnSort.Click
        If cv IsNot Nothing Then
            Await cv.SortAsync("Name", SortDirection.Ascending)
        End If
    End Sub
    
    private async void btnSort_Click(object sender, EventArgs e)
    {
        if (cv != null)
        {
            await cv.SortAsync("Name", SortDirection.Ascending);
        }
    }