I am trying to create a datagridview. And in one column i want to have different type of cells (hosting different editing controls). For example, in the same column first cell shall host a combo box control, second cell shall host a text box control, third cell shall host DateTime picker control, another with Colorpicker control, etc.

if i follow the host controls in windows forms Datagridview cell and currently if i change the cellTemplate property of DataGridViewColumn to calendarcell, then all the cells in that column become calendar cell. But instead i want to have a different control, for example colorpicker, in the next cell ie the one below this.

Please advise how to achieve this using datagridview cell.


Re: Windows Forms Designer how to host different controls in the same column in DataGridView control

Zhi-Xin Ye - MSFT

There're two ways to do this:

1). Cast a DataGridViewCell to a certain cell type that exists. For example, convert a DataGridViewTextBoxCell to DataGridViewComboBoxCell type.

2). Create a control and add it into the controls collection of DataGridView, set its location and size to fit the cell that to be host.

See my sample code below which illustrates the tricks.

Code Snippet

private void Form5_Load(object sender, EventArgs e)


DataTable dt = new DataTable();


for (int j = 0; j < 10; j++)




this.dataGridView1.DataSource = dt;

this.dataGridView1.Columns[0].Width = 200;


* First method : Convert to an existed cell type such ComboBox cell,etc


DataGridViewComboBoxCell ComboBoxCell = new DataGridViewComboBoxCell();

ComboBoxCell.Items.AddRange(new string[] { "aaa","bbb","ccc" });

this.dataGridView1[0, 0] = ComboBoxCell;

this.dataGridView1[0, 0].Value = "bbb";

DataGridViewTextBoxCell TextBoxCell = new DataGridViewTextBoxCell();

this.dataGridView1[0, 1] = TextBoxCell;

this.dataGridView1[0, 1].Value = "some text";

DataGridViewCheckBoxCell CheckBoxCell = new DataGridViewCheckBoxCell();

CheckBoxCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

this.dataGridView1[0, 2] = CheckBoxCell;

this.dataGridView1[0, 2].Value = true;


* Second method : Add control to the host in the cell


DateTimePicker dtp = new DateTimePicker();

dtp.Value = DateTime.Now.AddDays(-10);

//add DateTimePicker into the control collection of the DataGridView


//set its location and size to fit the cell

dtp.Location = this.dataGridView1.GetCellDisplayRectangle(0, 3,true).Location;

dtp.Size = this.dataGridView1.GetCellDisplayRectangle(0, 3,true).Size;


Re: Windows Forms Designer how to host different controls in the same column in DataGridView control


Thanks for this working example! First method worked perfect for me! :-)

Made my day!

Well, part of it...

I have now another DGV- or maybe DataSet-related problem down the line...

In order to get my changes saved I must leave the edited cell i DGV before saving my DataSet.

If I don't leave the cell my database won't be updated.

The DataSet seems to be updated, it displays correct in the DGV until I read from database again.

I have tried DGV.EndEdit() and DGV.CommitEdit() but no luck.

When I examine the DataSet in debug mode it seems ok. The new data is there, but it does reach the database.

I did also try DataRowVersion=Proposed on my DbParameter.

I used stored procedures and DiscoverParameter (EntLib3)

Any help would be appreciated!