Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.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 September 28th, 2006, 10:57 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default EditingControlShowing in DataGridView w 2 combobox

Hello fellow programmers,

I have a dataGridView with 2 comboBoxColumns amongst simple textboxColumns. When I click on the combo in column 4 everything is good grid_EditingControlShowing is called and rawComboChanged is called after it.

But when i then click on column 11, rawComboChanged is called immediately, skipping the call to grid_EditingControlShowing that should point the code towards currencyChanged method.

I think i found the problem: "The DataGridView reuses editing controls across cells if the type is the same"... But i dont have a solution... Can anyone help?

public void grid_EditingControlShowing(object sender, System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs e)
{
    DataGridView dataGridView = (DataGridView)sender;
    ComboBox comboBox = new ComboBox();
    if (dataGridView.CurrentCell.ColumnIndex == 4)
    {
        comboBox = e.Control as ComboBox;
        comboBox.SelectedIndexChanged += new System.EventHandler(this.rawComboChanged);
    }
    else if (dataGridView.CurrentCell.ColumnIndex == 11)
    {
         comboBox = e.Control as ComboBox;
         comboBox.SelectedIndexChanged += new System.EventHandler(this.currencyChanged);
    }
}

Mike
 
Old September 21st, 2010, 12:03 PM
Registered User
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Talking 4 years after...

Hi, I'm facing the same problem, and figured out that adding a line that substracts the event evertime it enters to the method event-catcher will fix the problem. this is my code:

private void dgConceptos_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridView dataGridView = (DataGridView)sender;
ComboBox comboBox = new ComboBox();
if (dataGridView.CurrentCell.ColumnIndex == 0)
{
comboBox = e.Control as ComboBox;
if (comboBox != null)
{
comboBox.SelectedIndexChanged -= new EventHandler(dgConceptosComboBoxDescripcion_Select edIndexChanged);
comboBox.SelectedIndexChanged += new EventHandler(dgConceptosComboBoxDescripcion_Select edIndexChanged);
}
}

}

private void dgConceptosComboBoxDescripcion_SelectedIndexChange d(object sender, EventArgs e)
{
ComboBox comboBox = (ComboBox)sender;

if (!string.IsNullOrEmpty(comboBox.Text))
{
some code here...
}
comboBox.SelectedIndexChanged -= new EventHandler(dgConceptosComboBoxDescripcion_Select edIndexChanged);
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
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 column p2pmarit .NET Framework 2.0 1 July 31st, 2006 02:31 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.