Click here to Skip to main content
12,752,448 members (36,487 online)
Click here to Skip to main content
Add your own
alternative version


69 bookmarked
Posted 9 Apr 2007

Multi Column Combo Cell for the .NET 2.0 DataGridView Control

, 25 Dec 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
This article will demonstrate an approach to solve the issue of a multi-column cell for DataGridView.



This article will demonstrate an approach to solve the issue of multi-column combobox cells in a DataGridView in VS8.

*New in this version

*After multiple comments that I got about the old implementation, I decided to make this solution nicer. I am following the solution using designed DataSet tables and dropping some workarounds and fixing some bugs I had in my first version!


Several months ago, I invested several days in order to find how to implement the multiline combobox issue. I found several solutions but they didn't fit my needs. I wanted something very simple. And I found it using the owner draw approach - just drawing a multicolumn control by myself. Here are the results.

Using the code

The code implementation and usage is extremely simple.

You do all the steps as you do if you want to embed a regular combobox into your DataGridView, but in place of the DataGridViewComboColumn, you use my class DataGridViewMultiColumnComboColumn. 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 in order 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.Insert(position, newColumn);
dataGridView1.Columns[position].Width = 300;

Points of interest

First, I am very happy that after 12 years of programming experience I found a way to contribute something small to this great professional discussion.

I am originally a C++/MFC programmer and I still work mostly using these programming languages. So I am strictly used to things that implement non-standard UIs. I think Microsoft did a great job developing the .NET platform. Anyway.

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 if it was helpful for somebody.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Israel Israel
Software Development freelancer.

You may also be interested in...


Comments and Discussions

Questionhow to create Combox Multi column In Datagridview column windows forms Pin
Member 1195074614-Sep-15 5:20
memberMember 1195074614-Sep-15 5:20 
QuestionColumns Header Text Pin
Biplob Singha Shee9-Feb-14 23:01
memberBiplob Singha Shee9-Feb-14 23:01 
Suggestionadd property to the code Pin
knight_dreams25-Jan-14 1:13
memberknight_dreams25-Jan-14 1:13 
SuggestionRe: add property to the code Pin
IssaharNoam27-Jan-14 10:11
memberIssaharNoam27-Jan-14 10:11 
GeneralRe: add property to the code Pin
knight_dreams10-Feb-14 11:01
memberknight_dreams10-Feb-14 11:01 
GeneralRe: add property to the code Pin
IssaharNoam11-Feb-14 2:19
memberIssaharNoam11-Feb-14 2:19 
QuestionValues of other members Pin
David 37-Jan-14 5:00
memberDavid 37-Jan-14 5:00 
AnswerRe: Values of other members Pin
IssaharNoam15-Jan-14 10:52
memberIssaharNoam15-Jan-14 10:52 
QuestionSystem.Data.DataRowView when using different datasource for column and Cells Pin
stupsnose_worldwide10-Aug-10 6:53
memberstupsnose_worldwide10-Aug-10 6:53 
AnswerRe: System.Data.DataRowView when using different datasource for column and Cells Pin
IssaharNoam10-Aug-10 11:05
memberIssaharNoam10-Aug-10 11:05 
GeneralRe: System.Data.DataRowView when using different datasource for column and Cells Pin
stupsnose_worldwide10-Aug-10 11:10
memberstupsnose_worldwide10-Aug-10 11:10 
AnswerRe: System.Data.DataRowView when using different datasource for column and Cells Pin
IssaharNoam10-Aug-10 13:11
memberIssaharNoam10-Aug-10 13:11 
QuestionSuggest or SuggestAppend Pin
Linoli1-Aug-10 4:08
memberLinoli1-Aug-10 4:08 
AnswerRe: Suggest or SuggestAppend Pin
IssaharNoam2-Aug-10 10:35
memberIssaharNoam2-Aug-10 10:35 
Generalvalue in the cell Pin
sergio5827-Mar-10 5:48
membersergio5827-Mar-10 5:48 
GeneralRe: value in the cell Pin
IssaharNoam28-Mar-10 14:37
memberIssaharNoam28-Mar-10 14:37 
GeneralColumns Width Pin
janeirish22-Mar-10 18:34
memberjaneirish22-Mar-10 18:34 
GeneralRe: Columns Width Pin
IssaharNoam23-Mar-10 12:26
memberIssaharNoam23-Mar-10 12:26 
Generalpopular manually Pin
sergio5821-Mar-10 6:11
membersergio5821-Mar-10 6:11 
GeneralRe: popular manually Pin
IssaharNoam21-Mar-10 10:41
memberIssaharNoam21-Mar-10 10:41 
GeneralRe: popular manually Pin
sergio5822-Mar-10 10:05
membersergio5822-Mar-10 10:05 
GeneralRe: popular manually Pin
IssaharNoam22-Mar-10 11:35
memberIssaharNoam22-Mar-10 11:35 
Generaldifferent use Pin
CICCIOLO6911-Mar-10 3:53
memberCICCIOLO6911-Mar-10 3:53 
GeneralRe: different use Pin
IssaharNoam11-Mar-10 11:06
memberIssaharNoam11-Mar-10 11:06 
GeneralRe: different use Pin
CICCIOLO6917-Mar-10 6:49
memberCICCIOLO6917-Mar-10 6:49 
GeneralRe: different use Pin
IssaharNoam17-Mar-10 10:17
memberIssaharNoam17-Mar-10 10:17 
GeneralRe: different use Pin
CICCIOLO6918-Mar-10 1:19
memberCICCIOLO6918-Mar-10 1:19 
GeneralRe: different use Pin
IssaharNoam18-Mar-10 11:54
memberIssaharNoam18-Mar-10 11:54 
GeneralVerry good work Pin
brindus9-Mar-10 23:39
memberbrindus9-Mar-10 23:39 
GeneralRe: Verry good work Pin
IssaharNoam11-Mar-10 11:10
memberIssaharNoam11-Mar-10 11:10 
GeneralHello Pin
liviucatrina8-Mar-10 4:40
memberliviucatrina8-Mar-10 4:40 
GeneralRe: Hello Pin
IssaharNoam8-Mar-10 9:18
memberIssaharNoam8-Mar-10 9:18 
GeneralAuto complete feature.. Pin
withsnaveen25-Oct-09 20:56
memberwithsnaveen25-Oct-09 20:56 
GeneralRe: Auto complete feature.. [modified] Pin
IssaharNoam28-Oct-09 12:57
memberIssaharNoam28-Oct-09 12:57 
GeneralSetting the selectedvalue for the dropdown.... Pin
Simon O'Farrell21-Oct-09 14:12
memberSimon O'Farrell21-Oct-09 14:12 
GeneralRe: Setting the selectedvalue for the dropdown.... Pin
IssaharNoam28-Oct-09 13:04
memberIssaharNoam28-Oct-09 13:04 
GeneralRe: Setting the selectedvalue for the dropdown.... Pin
Simon O'Farrell28-Oct-09 14:28
memberSimon O'Farrell28-Oct-09 14:28 
GeneralRe: Setting the selectedvalue for the dropdown.... Pin
IssaharNoam29-Oct-09 11:44
memberIssaharNoam29-Oct-09 11:44 
Questionhow to get value of Combobox columns in which event of datagridview. and display in netx cell Pin
Member 412614914-Oct-09 3:56
memberMember 412614914-Oct-09 3:56 
AnswerRe: how to get value of Combobox columns in which event of datagridview. and display in netx cell Pin
IssaharNoam14-Oct-09 12:16
memberIssaharNoam14-Oct-09 12:16 
Questionhow to get value of Combobox columns in which event of datagridview...??? [modified] Pin
Narendra Reddy Vajrala20-Aug-09 4:01
memberNarendra Reddy Vajrala20-Aug-09 4:01 
NewsImportant: My owner draw code contains GDI leaks, Please be aware to dispose all the allocate brushes and pens Pin
IssaharNoam9-Apr-09 13:56
memberIssaharNoam9-Apr-09 13:56 
GeneralSupporting IList as DataSource Pin
Kashif Iqbal Khan8-Apr-09 5:58
memberKashif Iqbal Khan8-Apr-09 5:58 
GeneralDropdown comobox cell in datagridview v2005 Pin
Samik_ Ray2-Apr-09 21:51
memberSamik_ Ray2-Apr-09 21:51 
GeneralRe: Dropdown comobox cell in datagridview v2005 Pin
IssaharNoam4-Apr-09 20:58
memberIssaharNoam4-Apr-09 20:58 
QuestionHow to add headers to combobox columns? Pin
mjbasecamp5-Mar-09 10:13
membermjbasecamp5-Mar-09 10:13 
AnswerRe: How to add headers to combobox columns? Pin
IssaharNoam5-Mar-09 11:12
memberIssaharNoam5-Mar-09 11:12 
GeneralDear Issahar: Pin
arevans24-Nov-08 10:10
memberarevans24-Nov-08 10:10 
GeneralRe: Dear Issahar: Pin
IssaharNoam25-Dec-08 6:56
memberIssaharNoam25-Dec-08 6:56 
QuestionAnyone have some more solid code? Pin
Member 359872110-Jun-08 9:12
memberMember 359872110-Jun-08 9:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 25 Dec 2008
Article Copyright 2007 by IssaharNoam
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid