We can add
DataGridViewComboBoxColumn control to a specified column of a Standard
DataGridView control that comes with .NET. There are some limitations with that control such as when entering a cell it is not popup that displays its content. Another thing is there is limited number of component support with
DataGridView such as
DataGridViewComboBoxColumn, etc. It is difficult to add additional components to
In this article, I have discussed how to develop a control that inherits standard features of
DataGridView and adds additional features to that control. By locking this
NewDataGridView control, you will be able to develop a
DataGridView control adding many more features as you wish.
Using the Code
How to add this control to your project?
AdvListBox projects or its DLL to your solution.
How to Add this Control into your Form?
Drag and drop
NewDataGridView control from ToolBox into your form.
How to add ListBox to DataGridView Control?
NewGridView control to your form, you should add
ListBox according to your requirements. Note: Before you add
ListBox, columns should be added to the
Listbox can be added through the property window of
NewDataGridView control. Use ListBox Details section.
After adding a
ListBox, you should bind it with a particular column of
NewDataGridView. To do that, you have to use Binding Column section of property window of
Now you have to define
EventHandler for each
ListBox that you have added to the
NewDataGridView component for assigning a selected item to a cell and hide that
ListBox when double clicked on the
listbox. Here is the code for that:
public partial class Form1 : Form
int rowIndex, columnIndex;
void ListBox1_DoubleClick(object sender, EventArgs e)
this.newDataGridView1[columnIndex, rowIndex].Value =
this.newDataGridView1.ListBoxCollection.Visible = false;
private void newDataGridView1_CellEnter
(object sender, DataGridViewCellEventArgs e)
rowIndex = e.RowIndex;
columnIndex = e.ColumnIndex;
private void btnClose_Click(object sender, EventArgs e)
private void btnAddRow_Click(object sender, EventArgs e)
- 7th March, 2008: Initial post