How to use Advanced Filter DataGridView in C#
By FoxLearn 7/20/2024 2:33:00 AM 24.25K
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.
How to use Advanced DataGridView to filter data in C#
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 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(); } 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; } // RowFilter datagridview C# 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); } } }
Through this example you can easily use Advanced DataGridView to filter datagridview like excel in c#
VIDEO TUTORIALS
- How to make a Notepad in C#
- How to Receive SMS from WhatsApp in C#
- How to Add Combobox to DataGridView in C#
- How to Create Multiple pages on the Form using Panel control in C#
- How to insert Math Equation to RichTextBox in C#
- How to Send and Receive email in Microsoft Outlook using C#
- How to Print Windows Form in C#
- How to Use Form Load and Button click Event in C#