How to use Advanced Filter DataGridView in C#
By FoxLearn 1/14/2025 4:09:51 AM 25.87K
AdvancedDataGridView control is a .NET WinForms DataGridView with advanced Filtering and Sorting capabilities. It's a third-party libraries and extensions that provide advanced functionalities for DataGridView, which is a native control in Windows Forms for displaying and editing tabular data.
It offers additional features such as sorting, filtering, grouping, and hierarchical display capabilities, which are not available in the standard DataGridView.
C# DataGridView Search Filter
Open your Visual Studio, then click New Project. Next, select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "AdvancedDataGridViewDemo" and then click OK
To play demo, you need to install AdvancedDataGridView by right-clicking on your project, then select Manage NuGet Packages -> Search for AdvancedDataGridView
-> Install
Advanced DataGridView is a custom of Windows Forms DataGridView Control with Excel-Like auto-filter context menu.
Here are the general steps to use the AdvancedDataGridView
control in C#.
We will get data from sql database then populate it into Advanced DataGridView. Using the Advanced DataGridView control allows you to easily filter datagridview in c#
I'll create a dataset, then add the customers table from the Northwind database to my dataset.
DataSet is an in-memory cache of data retrieved from a data source, typically a database.
Advanced filter DataGridView in C#
After installing the AdvancedDataGridView, you need to rebuild your project.
You should now be able to find the AdvancedDataGridView
control in your toolbox. Next, open your Form designer, then drag the AdvancedDataGridView from the Visual Studio toolbox onto your form designer.
Add a bindingsource control to the Advanced DataGridView allows you to fetch the customer data from the Northwind database.
Finally, Add code to handle your winform as below
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; // datagridview with filtering capability c# namespace AdvancedDataGridViewDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } // datagridview filter c# form_load event handler private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'northwindDataSet.Customers' table. You can move, or remove it, as needed. this.customersTableAdapter.Fill(this.northwindDataSet.Customers); } // DG advanceddatagridview sort private void advancedDataGridView_SortStringChanged(object sender, EventArgs e) { this.customersBindingSource.Sort = this.advancedDataGridView.SortString; } // advanced datagridview filter c# with rowfilter private void advancedDataGridView_FilterStringChanged(object sender, EventArgs e) { this.customersBindingSource.Filter = this.advancedDataGridView.FilterString; } private void customersBindingSource_ListChanged(object sender, ListChangedEventArgs e) { lblTotal.Text = string.Format("Total rows: {0}", this.customersBindingSource.List.Count); } } }
This example demonstrates how to use Advanced DataGridView in C# to filter a DataGridView similar to Excel.
VIDEO TUTORIAL
- How to Create a custom Progress Bar with Percentage in C#
- How to update UI from another thread in C#
- How to Create a Wait Form Dialog in C#
- How to Get all Forms and Open Form with Form Name in C#
- How to Print DataGridView with Header & Footer with Landscape in C#
- How to Add Combobox to DataGridView in C#
- How to Hide a WinForm in C#
- How to zoom an image in C#