# Filtering

This topic covers the filtering functionality of DataCollection.

## Content



Data Collection implements the [ISupportFiltering](/componentone/api/services/online-datacollection/dotnet-standard-api/C1.DataCollection/C1.DataCollection.ISupportFiltering.html) interface to support filtering, which enables you to filter data using the [FilterAsync](/componentone/api/services/online-datacollection/dotnet-standard-api/C1.DataCollection/C1.DataCollection.IDataCollectionEx.FilterAsync.html) method. This method calls the filtering operation and refines the data collection according to the user requirements without including any repetitive or irrelevant data.

**IDataCollection** provides 5 overloads of [FilterAsync](/componentone/api/services/online-datacollection/dotnet-standard-api/C1.DataCollection/C1.DataCollection.IDataCollectionEx.FilterAsync.html) method. Refer this [topic](/componentone/api/services/online-datacollection/dotnet-standard-api/C1.DataCollection/C1.DataCollection.IDataCollectionEx.FilterAsync.html) to know more about these overloads. In the example depicted, we have used FilterAsync\<T>(IDataCollection\<T>,Expression<Func<T,Object>>,FilterOperation,Object) method overload, which filters the data using specified filter parameters in the DataGridView. The **FilterAsync** method uses data collection, filterPath, filterOperation and value as its parameters. Here, 'filterPath' refers to the path of the data item to which the filter is applied, 'filterOperation' refers to the specific filter operation and 'value' refers to the value used in the expression.

The GIF below depicts filtering the data grid by Names that begin with 'He' value.

![The image shows filtering in an application.](https://cdn.mescius.io/document-site-files/images/61bca276-a017-410c-b2f2-8d6dca57ae3b/images/filtering_dcoll.gif)

The following code uses the sample created in the [Quick Start](/componentone/docs/services/online-datacollection/quickstart) section. Note that, the filterPath parameter used here is 'Name'. Also, the [FilterOperation](/componentone/api/services/online-datacollection/dotnet-standard-api/C1.DataCollection/C1.DataCollection.FilterOperation.html) enumeration uses the **StartsWith** field to filter all the names that start with 'He'.

### WinForms

This is the C# Code for Filtering in WinForms applications:

```csharp
// Filter data using FilterAsync method
private async void btn_filter_Click(object sender, EventArgs e)
{
    await cv.FilterAsync("Name", FilterOperation.StartsWith, "He");
}
```

This is the VB Code for Filtering in WinForms applications:

```vbnet
' Filter data using FilterAsync method
Private Async Sub btn_filter_Click(sender As Object, e As EventArgs) Handles btn_filter.Click
    Await cv.FilterAsync("Name", FilterOperation.StartsWith, "He")
End Sub
```

### WPF

This is the C# code for filtering in WPF applications:

```csharp
// Filter data using FilterAsync method
private async void btn_Filter_Click(object sender, RoutedEventArgs e)
{
    await cv.FilterAsync("Name", FilterOperation.StartsWith, "He");
}
```

This is the VB code for filtering in WPF applications:

```vbnet
' Filter data using FilterAsync method
Private Async Function Btn_filter_ClickAsync(sender As Object, e As RoutedEventArgs) As Task Handles btn_filter.Click
    cv = New C1DataCollection(Of Customer)(Customer.GetCustomerList(100))
    grid.ItemsSource = cv
    Await cv.FilterAsync("Name", FilterOperation.StartsWith, "He")
End Function
```

### Xamarin

This is the code snippet for Xamarin Forms:

```XAMARIN
// Filter data using FilterAsync method
public Filtering()
{
    InitializeComponent();
    C1DataCollection<Customer> datacol = new C1DataCollection<Customer>(Customer.GetCustomerList(250));
    grid.ItemsSource = datacol;
    datacol.FilterAsync("Jammers");
}
```

This is the code snippet for Android:

```ANDROID
// Filter data using FilterAsync method
var data = Customer.GetCustomerList(100);
grid.ItemsSource = data;           ((C1DataCollection<object>)grid.DataCollection).FilterAsync("Jammers");
FullTextFilterBehavior fullTextFilter = new FullTextFilterBehavior();
fullTextFilter.HighlightColor = Color.Blue;
fullTextFilter.Attach(grid);
fullTextFilter.FilterEntry = textbox;
```

This is the code snippet for iOS:

```IOS
// Filter data using FilterAsync method                 
((C1DataCollection<object>)Grid.DataCollection).FilterAsync("Jammers");
fullTextFilter = new FullTextFilterBehavior();
fullTextFilter.HighlightColor = UIColor.Blue;
```