Multi Column Combo Cell for a .NET 2.0 DataGridView Control


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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.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.

About the Author

Issahar Noam Gourfinkel

Sofware Development Freelancer



  • IT Administrator

    Posted by vinod on 11/20/2014 04:24am

    Thanks a lot for placing the code. please help how can I get gridview combobox selected event to get all the three columns value inside the combobox Thanks.

  • Thanks a lot

    Posted by Arun on 06/22/2012 11:05am

    Very useful article. Thanks

  • thank you

    Posted by Tran Cao Thang on 04/13/2012 10:10am

    I 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

  • mysql

    Posted by narcisofaria on 06/01/2011 02:13pm

    is it possible for it to work with a mysql database Greetings Narcissus would

  • ds

    Posted by narcisofaria on 06/01/2011 12:28pm

    good day
    the class is actually very well done, so I do not understand the code above that is the subject: ds?
    If I can clarify ffectiveness very grateful.
    Narciso Faria

  • Really helped me but.....

    Posted by narendra_vajrala@yahoo.co.in on 08/20/2009 03:55pm

    Hello, 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

    • Response

      Posted by IssaharNoam on 08/24/2009 12:29am

      Hi, 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

  • checkbox column

    Posted by Buster95 on 05/17/2007 04:22am

    Very Nice. Add a checkbox column?

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date