Multi Column Combo Cell for a .NET 2.0 DataGridView Control
Several months ago, I invested several days' work to find how to implement the multiline combobox in VS8 DataGridView control. I found several solutions but they didn't fit my needs. I wanted something very simple. And I found it by using Owner Draw approach—just drawing a multicolumn control by myself. Here are the results.
The code implementation and usage is extremely simple.
*New in this version
*After multiple comments that I have got about the old implementation, I decided to make this solution nicer. Following the solution using designed DataSet tables and dropping some workarounds and fixing some bugs I had in my first version!
You do all the steps as you do if you want to embed the regular combobox into your DataGridView, but in place of the DataGridViewComboColumn, you use my DataGridViewMultiColumnComboColumn class. This class is derived from DataGridViewComboColumn. Additionally, you need to set the column CellTemplate with the DataGridViewMultiColumnComboCell class that is derived from DataGridViewMultiColumnComboCell. After creating the DataGridViewMultiColumnComboCell class, you will need to set two data members to allow the multiline combobox to display the relevant values.
//create the multicolumncombo column
DataGridViewMultiColumnComboColumn newColumn =
new DataGridViewMultiColumnComboColumn();
newColumn.CellTemplate = new DataGridViewMultiColumnComboCell();
//Set the source table settings from the database for combobox values
newColumn.DataSource = ds.LogMessageTypes;
newColumn.DisplayMember = ds.LogMessageTypes.TypeNameColumn.ColumnName;
newColumn.ValueMember = ds.LogMessageTypes.TypeIdColumn.ColumnName;
//this property point on main table of this grid to bind to this column
newColumn.DataPropertyName = ds.LogTable.TypeColumn.ColumnName;
newColumn.HeaderText = ds.LogTable.TypeColumn.ColumnName;
newColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
dataGridView1.Columns.Remove(ds.LogTable.TypeColumn.ColumnName);
dataGridView1.Columns.Insert(position, newColumn);
dataGridView1.Columns[position].Width = 300;
First, I am very happy that, after 10 years of programming experience, I found the way to contribute something small to this great professional discussion.
I am originally a C++/MFC programmer and I still work mostly in these programming languages. So, I was strictly used to thinking that implementing a non-standard UI is a piece of work. So, I think Microsoft did a great job when it developed the .NET platform.
BTW: I still love developing ActiveX in C++, but there is no client that wants it anymore and I can understand why.
Disclaimer of Warranty
All of the code, information, instructions, and recommendations in this article are offered on a strictly "as is" basis. This material is offered as a free public resource, without any warranty, expressed or implied.
This code is completely free. I will be happy to know it it was helpful for somebody.

Comments
Thanks a lot
Posted by Arun on 06/22/2012 04:05amVery useful article. Thanks
Replythank you
Posted by Tran Cao Thang on 04/13/2012 03:10amI happy from the article: "Multi Column Combo Cell for a .NET 2.0 DataGridView Control" I am Vietnamese so My english is not good to write more than I Happy
Replymysql
Posted by narcisofaria on 06/01/2011 07:13amis it possible for it to work with a mysql database Greetings Narcissus would
Replyds
Posted by narcisofaria on 06/01/2011 05:28amReally helped me but.....
Posted by narendra_vajrala@yahoo.co.in on 08/20/2009 08:55amHello, Isshar! this article was really helped me alot in coding n time also very thanks a small requirement: in my c#.net 3.5 windows application, i have a datagridview to that datagridview i added a datagridviewcomboboxcolumn, values comming everything fine till here. based on the section of that combobox value i have to fill the remaining cell values to that perticular row. i wrote code in dataGridView1_CellClick event { if (e.ColumnIndex == 1) { int rowNo = e.RowIndex; string prId = dataGridView1.Rows[rowNo].Cells[1].Value.ToString(); based on prId am retrieving values and filling remaining cells to that row. } } but the problem is 1) it is not filling the remaining cells at the time of selecting that perticular comboboxcolumn 2)If i leave that cell and comeagain to that cell then remaining cells were filling i tried in cell Leave event and cellValuechanged event also but no use am sure that i am calling this in some wrong event which is not suitable to this requirement can anybody shed some light on this on which Datagridview event i have to call this to effect that row based on the selection of cell(comboboxColumn cell) please help me out Thankyou very much once again --Naren vnreddy@vercom.com-
ReplyResponse
Posted by IssaharNoam on 08/23/2009 05:29pmHi, Naren! If I am not wrong, you should listen for EditingControlShowing DataGridEvent and cast the event Control property to combobox and register your own events to listen it's events. Don't forget to unregister these events on CellEndEdit event. Issahar
Replycheckbox column
Posted by Buster95 on 05/16/2007 09:22pmVery Nice. Add a checkbox column?
Reply