DataGridView Autocomplete TextBox

Presenting data in a tabular format is a recurring task that is frequently encountered in various professional settings. To fulfill this requirement with utmost efficiency, the C# DataGridView control emerges as an indispensable tool, boasting exceptional configurability and extensibility. With its extensive repertoire of properties, methods, and events, this control empowers developers with a wide array of options to meticulously tailor both the display and behavior of the tabular representation.

The inherent flexibility of the C# DataGridView control allows for seamless customization to meet specific data presentation needs. Developers have the ability to fine-tune visual attributes such as column widths, cell formatting, and styling, enabling the creation of visually appealing and intuitive table layouts. Additionally, this control's versatility extends to the manipulation of data itself, with comprehensive support for sorting, filtering, and grouping operations, among others, ensuring that the presented information aligns precisely with the intended requirements.

DataGridView Autocomplete TextBox in C#


C# AutoComplete in DataGridView

In C# you can display DataGridView in Bound mode, unbound mode and Virtual mode . Bound mode is suitable for managing data using automatic interaction with the data store. The common use of the DataGridView control is binding to a table in a database. The data can be displayed in the DatagridView using TextBox, ComboBox, CheckBox etc. While you display the data on TextBox, you can make your TextBoxes as Autocomplete TextBox.

AutoComplete in DataGridView

C# Autocomplete TextBox

The TextBox control offers a range of properties, such as AutoCompleteCustomSource, AutoCompleteMode, and AutoCompleteSource, that facilitate the automatic completion of user input strings. This feature enhances user convenience by comparing the entered prefix letters to the prefixes of all strings within a designated data source, thereby enabling seamless and efficient input completion.

The following C# program shows how to create an AutoComplete Textbox inside a DataGridView.

Full Source C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { dataGridView1.ColumnCount = 3; dataGridView1.Columns[0].Name = "Product ID"; dataGridView1.Columns[1].Name = "Product Name"; dataGridView1.Columns[2].Name = "Product Price"; string[] row = new string[] { "1", "Product 1", "1000" }; dataGridView1.Rows.Add(row); row = new string[] { "2", "Product 2", "2000" }; dataGridView1.Rows.Add(row); row = new string[] { "3", "Product 3", "3000" }; dataGridView1.Rows.Add(row); row = new string[] { "4", "Product 4", "4000" }; dataGridView1.Rows.Add(row); } private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { string titleText = dataGridView1.Columns[1].HeaderText; if (titleText.Equals("Product Name")) { TextBox autoText = e.Control as TextBox; if (autoText != null) { autoText.AutoCompleteMode = AutoCompleteMode.Suggest; autoText.AutoCompleteSource = AutoCompleteSource.CustomSource; AutoCompleteStringCollection DataCollection = new AutoCompleteStringCollection(); addItems(DataCollection); autoText.AutoCompleteCustomSource = DataCollection; } } } public void addItems(AutoCompleteStringCollection col) { col.Add("Product 1"); col.Add("Product 2"); col.Add("Product 3"); col.Add("Product 4"); col.Add("Product 5"); col.Add("Product 6"); } } }


The C# DataGridView control stands as a powerful tool for the consistent and professional presentation of data in a tabular format. Its remarkable configurability, extensibility, and comprehensive suite of properties, methods, and events empower developers to effortlessly customize the display and behavior of the control, ensuring that the resulting tabular representation aligns perfectly with the specific requirements of each professional context.