?
Solved

DataGridview - ComboBox

Posted on 2007-10-19
7
Medium Priority
?
514 Views
Last Modified: 2009-12-16
I have a DataGridView with 2 comboBoxColumns.  When I click on the combo in column 2 everything is good dgv_EditingControlShowing is called and rawComboChanged is called after it.  

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

public void dgv_EditingControlShowing(object sender, System.Windows.Forms.DataGridViewEditingControlShowingEventArgs e)
{
    DataGridView dataGridView = (DataGridView)sender;
    ComboBox cb = new ComboBox();
    if (dataGridView.CurrentCell.ColumnIndex == 2)
    {
        cb= e.Control as ComboBox;
        cb.SelectedIndexChanged += new System.EventHandler(this.rawComboChanged);
    }
    else if (dataGridView.CurrentCell.ColumnIndex == 3)
    {
         cb= e.Control as ComboBox;
         cb.SelectedIndexChanged += new System.EventHandler(this.currencyChanged);
    }
}

does anyone know how to fix it?
0
Comment
Question by:smaguire
  • 3
  • 3
6 Comments
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20112771
Can you post the code from YourForm.Designer.cs where the event handlers are added?

Jim
0
 

Author Comment

by:smaguire
ID: 20123298
Sorry Jim for the delay,

here is both of my methods:

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

                // now attach the event handler
                cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
            }
        }

        void cb_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedUnitName;
            selectedUnitName = cb.Text;
            SetComboBoxDataSource(comboboxMyColumn, "MyName", selectedUnitName);
            comboboxMyColumn.HeaderText = "Mill";
            //MessageBox.Show("Selected index changed");
            comboboxMyColumn.Selected = true;  
        }

only the first time it goes through the first method, and when i click the second time it goes directly to the second method (SelectedIndexChanged) Ignoring the first method.

thanks you
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20128262
That's the event handler. Can you post the code where you assigned the event handler to the event?

Jim
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:smaguire
ID: 20130797
here it is:
this.dgvChanConfig.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(this.dgvChanConfig_EditingControlShowing);

thanks
0
 
LVL 22

Accepted Solution

by:
JimBrandley earned 1000 total points
ID: 20159982
I'm guessing he solved it himself, and that's fine with me.

Jim
0
 

Author Comment

by:smaguire
ID: 20166398
hi Jim,
thanks for your reply, I went with a different solution but I will give you the points for trying to help me out.

thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question