Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 28th, 2006, 10:57 AM
Registered User
 
Join Date: Sep 2006
Location: london, , .
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
Reply With Quote
  #2 (permalink)  
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);
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.