# Visualize Query using DataEngineCollection

Visualize queries using the DataEngineCollection assembly.

## Content



This walkthrough depicts a scenario where the user can visualize a query using **DataEngineCollection** in a **WinForms** application. The app presents a **DataGridView** control, whose source is a **C1DataEngineCollection** created from a query. The example further shows how the DataEngineCollection allows the final users to sort and filter any query easily through the native DataGridView column headers and use a text-box to filter a column as the users types in it.

![](https://cdn.mescius.io/document-site-files/images/09dc0709-b6e6-44f2-a87a-75d899f9cf2c/images/datagrid-filtering-firstname.png)

To learn how to visualize queries using the **DataEngineCollection**, follow the steps given below:

1.  Create a **Windows Forms App** using C# .NET.
    
2.  Add the following assemblies to the project:
    
    *   **C1.DataCollection.BindingList**
    *   **C1.DataEngine**
    *   **C1.DataEngine.Collection**
3.  Switch to the Design View.
    
4.  Drop the following controls onto the form:
    
    *   **DataGridView** - Uncheck the Enable Editing from the DataGridView Tasks menu.
    *   **TextBox** - Add the PlaceholderText as 'FirstName filter' using the Properties window.
    *   **StatusStrip** - Add the StatusLabel to the StatusStrip control using the dropdown icon.
    
    The form should like this:
    
    ![](https://cdn.mescius.io/document-site-files/images/09dc0709-b6e6-44f2-a87a-75d899f9cf2c/images/form-controls.png)
    
5.  Switch to the code view. Initialize the **Workspace** and **IDataCollection** objects.
    
    ```csharp
    private Workspace _workspace;
    private IDataCollection<object> _dataCollection;
    ```
    
6.  Generate the **LoadAsync** function. Add the following code to the function:
    
    ```csharp
    private async Task LoadAsync()
            {
                toolStripStatusLabel1.Text = "Generating data...";
                await Task.Yield();
                _workspace = new Workspace();
                _workspace.Init("workspace");
                if (!DataService.TablesExist(_workspace))
                {
                    await DataService.GenerateData(_workspace);
                }
                _dataCollection = await DataService.LoadDataCollection(_workspace);
                dataGridView1.DataSource = new C1DataCollectionBindingList(_dataCollection);
                _dataCollection.CollectionChanged += _dataCollection_CollectionChanged;
                this.FormClosed += (s, e) => ((IDisposable)_dataCollection).Dispose();
                UpdateStatus();
            }
    ```
    
    As you can observe from the above code snippet, the DataGridView is bound to the DataCollectionBindingList, and the DataCollection extracts the data from the **DataService** class (which is taken from the **DataSource.cs** file in the **DataEngineCollectionSample**). Further, we have also initialized the **UpdateStatus** function.
    
7.  Add the following code to the UpdateStatus function.
    
    ```csharp
    private void UpdateStatus()
       {
          toolStripStatusLabel1.Text = string.Format("Count: {0}", _dataCollection.Count);
       }
    ```
    
    We have assigned the **Text** property of the **ToolStripStatusLabel** to show the count of the filtered data at runtime.
    
8.  Add the following code to the **CollectionChanged** event of DataCollection, which occurs when the collection is changed.
    
    ```csharp
    private void _dataCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        UpdateStatus();
    }
    ```
    
9.  Add the following code to the **TextChanged** event of the TextBox. Add the **FilterAsync** method of the DataCollection so that you can filter asynchronously the FirstName from the list of data in the DataGridView. This method passes the **FilterExpression** property of **C1DataEngineCollection** class, which gets the filter expression applied to the data.
    
    ```csharp
    private void searchBox_TextChanged(object sender, System.EventArgs e)
    {
        _dataCollection.FilterAsync(FilterExpression.FromString(searchBox.Text, new string[] { "FirstName" }));
    }
    ```
    


> type=note
> **Note**: This walkthrough is available in the **DataEngineCollectionSample**.