Windows Forms: Search DataGridView by using ComboBox and TextBox in C#

How to Search/Filter DataGridView by using ComboBox and TextBox in C#.

Step 1Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "SearchDataGridViewUsingComboBoxTextBox" and then click OK

search datagridview in c#Step 2: Design your form as below

c# search datagridview

Step 3: Create a new dataset, then add a Product table from Northwind database to your dataset

c# dataset

Step 4: Add code to handle your form 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;

namespace SearchDataGridViewUsingComboBoxTextBox
    public partial class Form1 : Form
        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            // TODO: This line of code loads data into the 'database.Products' table. You can move, or remove it, as needed.
            cboColumn.SelectedIndex = 1;

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
            //Filter data
            if (e.KeyCode == Keys.Enter)
                if (string.IsNullOrEmpty(txtSearch.Text))
                    productsBindingSource.Filter = string.Empty;
                    productsBindingSource.Filter = string.Format("{0}='{1}'", cboColumn.Text, txtSearch.Text);