DatagridView in C# 2015 is an important tool to show database values. This control has different usage such as regular Grid. Here we explore the different approaches to the datagrid programing which will explaining how to add advanced combo, auto suggestion box etc to DataGridView control.
Easy steps we require
Start a new Windows Form project in your Visual Studio and Drop a DatagridView control to your project, our project require a DataGridViewComboBoxColumn object. Here we goes
- Initialize column header with appropriate text
- Create a DataGridViewComboBoxColumn object and fill with appropriate values, name and a header text.
- Add the DataGridViewComboBoxColumn object to the DatagridView
That’s the plan, just the drop the following code to the form’s load event method.
The C# code
dataGridView1.ColumnCount = 1;
dataGridView1.Columns[0].Name = “Slno”;
DataGridViewComboBoxColumn dc = new DataGridViewComboBoxColumn();
dc.HeaderText = “Order Items”;
dc.Name = “Items”;
dc.Items.Add(“Mango”);
dc.Items.Add(“Carrot”);
dc.Items.Add(“Sugar cane”);
dc.Items.Add(“Potatto”);
dc.Items.Add(“Grapes”);
dc.Items.Add(“Chillie”);
dc.MaxDropDownItems = 1;
dataGridView1.Columns.Add(dc);
dataGridView1.Columns.Add(“Qty”, “Qty”);
dataGridView1.Columns[0].Name = “Slno”;
DataGridViewComboBoxColumn dc = new DataGridViewComboBoxColumn();
dc.HeaderText = “Order Items”;
dc.Name = “Items”;
dc.Items.Add(“Mango”);
dc.Items.Add(“Carrot”);
dc.Items.Add(“Sugar cane”);
dc.Items.Add(“Potatto”);
dc.Items.Add(“Grapes”);
dc.Items.Add(“Chillie”);
dc.MaxDropDownItems = 1;
dataGridView1.Columns.Add(dc);
dataGridView1.Columns.Add(“Qty”, “Qty”);
Lets run, and that’s all you need to know. Next time we will meet with Autocomplete Box poem.