Click here to Skip to main content
15,892,517 members
Home / Discussions / C#
   

C#

 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute19-May-10 1:15
Henry Minute19-May-10 1:15 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 3:49
mprice21419-May-10 3:49 
GeneralRe: ComboBox selection generating list for another comboBox question [modified] Pin
Henry Minute19-May-10 4:22
Henry Minute19-May-10 4:22 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 4:43
mprice21419-May-10 4:43 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute19-May-10 5:07
Henry Minute19-May-10 5:07 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 5:29
mprice21419-May-10 5:29 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 18:46
mprice21419-May-10 18:46 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute20-May-10 1:35
Henry Minute20-May-10 1:35 
Aaaaand relax!

I think I know what is going on here. If you recall, well even if you don't recall actually Smile | :) , in my second message to you I had this bit of code:
(I've annotated it a bit and modified it v,v slightly)
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
   ComboBox cb;

   // switch (dataGrid.CurrentCell.ColumnIndex)   <===================================== silly! already have column in eventargs
   switch (e.Column)                              //<==============================Use this instead
   {
       case 0:  // use the index for your comboboxcolumn    <============ <big>V IMPORTANT</big> make sure that the 0: matches the index for your column
           cb = e.Control as ComboBox;
           if (cb != null)
           {
           // first remove event handler to keep from attaching multiple:
           cb.SelectedIndexChanged -= column1DataGridViewComboBox_SelectedIndexChanged;
           // now attach the event handler
           cb.SelectedIndexChanged += column1DataGridViewComboBox_SelectedIndexChanged;
           }
           break;
        // <================================== You do not need the part below since you only need it to apply to the first cbcolumn
      //case 3: // use the index for your second combo
        //   cb = e.Control as ComboBox;
          // if (cb != null)
           //{
           // first remove event handler to keep from attaching multiple:
         //  cb.SelectedIndexChanged -= cb_SecondSelectedIndexChanged;
           // now attach the event handler
          // cb.SelectedIndexChanged += cb_SecondSelectedIndexChanged;
           //}
           //break;
   }
}


If you can absolutely guarantee that you will only want to do this for one ComboBoxColumn you can simplify the code slightly.
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
   ComboBox cb;

   // replace the switch statement by an if statement
   if (e.Column == 0)  //<============ <big>V IMPORTANT</big> change the 0 (if necessary) to  match the index for your column
   {
           cb = e.Control as ComboBox;
           if (cb != null)
           {
           // first remove event handler to keep from attaching multiple:
           cb.SelectedIndexChanged -= column1DataGridViewComboBox_SelectedIndexChanged;
           // now attach the event handler
           cb.SelectedIndexChanged += column1DataGridViewComboBox_SelectedIndexChanged;
           }
    }
}


If you do not check that we are dealing with the correct column before applying the link to the SelectedIndexChanged handler, it will get applied to any and all ComboBoxColumns in the grid.

If this does not resolve the issue, please come back.

Good luck! Smile | :)
Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.

GeneralRe: ComboBox selection generating list for another comboBox question [modified] Pin
mprice21420-May-10 3:44
mprice21420-May-10 3:44 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute20-May-10 5:23
Henry Minute20-May-10 5:23 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21426-May-10 19:10
mprice21426-May-10 19:10 
AnswerRe: ComboBox selection generating list for another comboBox question Pin
William Winner18-May-10 7:31
William Winner18-May-10 7:31 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 7:58
mprice21418-May-10 7:58 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
William Winner18-May-10 11:12
William Winner18-May-10 11:12 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 12:16
mprice21418-May-10 12:16 
QuestionRemoting Service Pin
Britt Mills18-May-10 4:21
Britt Mills18-May-10 4:21 
AnswerRe: Remoting Service Pin
canangirgin18-May-10 4:48
canangirgin18-May-10 4:48 
GeneralRe: Remoting Service Pin
Britt Mills18-May-10 4:56
Britt Mills18-May-10 4:56 
GeneralRe: Remoting Service Pin
canangirgin20-May-10 21:20
canangirgin20-May-10 21:20 
QuestionIE Page size Pin
dSolariuM18-May-10 3:21
dSolariuM18-May-10 3:21 
AnswerRe: IE Page size Pin
Kevin Marois18-May-10 5:10
professionalKevin Marois18-May-10 5:10 
GeneralRe: IE Page size Pin
Luc Pattyn18-May-10 5:58
sitebuilderLuc Pattyn18-May-10 5:58 
GeneralRe: IE Page size Pin
Kevin Marois18-May-10 6:00
professionalKevin Marois18-May-10 6:00 
QuestionOutlook 2007 - Editing calendar information Pin
lvq68418-May-10 3:11
lvq68418-May-10 3:11 
AnswerRe: Outlook 2007 - Editing calendar information Pin
OriginalGriff18-May-10 4:53
mveOriginalGriff18-May-10 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.