Wrox Programmer Forums
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 26th, 2006, 08:02 AM
Registered User
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagridview & combobox column

Please help me with my DataGridView...

I have got a DataGridView with a ComboBoxColumn.

I have set the DGV datasource to a table and I have populated the CBC by just adding items like this:
Me.colPosition.Items.Add(value), where value is an () of data.

Now, my questions are many, but firstly:

I really miss the properties & events that a regular combobox has, like selectedItem & selectedIndexChanged…
Or how do I deal with the usual stuff like setting the selectedIndex = 0 and getting the selectedItem like I normally do with a regular comboBox???

Is a conversion from a cell in the comboboxcolumn to a regular combobox necessary, or how do I do this?

I also get an Data error when I select something from my CBC and leave the CBC...

ANY suggestions are welcomed at this point!

Thanks you very much!

:O )
Old July 31st, 2006, 02:31 AM
Registered User
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Sometimes it is helpful to know when a user has selected an item in the ComboBox editing control. With a ComboBox on your form you would normally handle the SelectedIndexChanged event. With the DataGridViewComboBox you can do the same thing by using the DataGridView.EditingControlShowing event. The following code example demonstrates how to do this. Note that the sample also demonstrates how to keep multiple SelectedIndexChanged events from firing.

private void dataGridView1_EditingControlShowing(object sender,
                    DataGridViewEditingControlShowingEventArgs e)
    ComboBox cb = e.Control as ComboBox;
    if (cb != null)
        // first remove event handler to keep from attaching multiple:
        cb.SelectedIndexChanged -= new

        // now attach the event handler
        cb.SelectedIndexChanged += new

void cb_SelectedIndexChanged(object sender, EventArgs e)
    MessageBox.Show("Selected index changed");

With Regards,
Ravi Madangallu

Similar Threads
Thread Thread Starter Forum Replies Last Post
EditingControlShowing in DataGridView w 2 combobox mike_geomatics .NET Framework 2.0 1 September 21st, 2010 12:03 PM
ComboBox events in dataGridView mallikalapati Visual Studio 2005 0 February 27th, 2008 07:16 AM
DataGridView ComboBox StuckAgain C# 2005 1 February 22nd, 2008 09:59 AM
2 comboBox in the DataGridView mehrdad_T C# 0 January 20th, 2008 07:27 AM
Datagridview combobox issue aad1 C# 0 May 26th, 2006 01:00 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.