Click here to Skip to main content
15,919,132 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: ComboBox selection generating list for another comboBox question [modified] Pin
mprice21420-May-10 3:44
mprice21420-May-10 3:44 
Good morning (or whatever time of day it is to you). DataGridViewEditingControlShowingEventArgs does not contain the "column" method. I do remember your second message and did try to do that yesterday without success. Let me give you both methods together:

private void column1DataGridViewComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

            
            ComboBox cb = sender as ComboBox;

          
            int intPrimary = cb.SelectedIndex;
            Debug.WriteLine(intPrimary + "SelectedIndexChanged");

            var dataSource = new List<Units>();

            switch (intPrimary)
            {
                case 0:
                    
                //Build a list 
                
                dataSource.Add(new Units() { Unit = "blah1" });
                dataSource.Add(new Units() { Unit = "blah2" });
                dataSource.Add(new Units() { Unit = "blah3" });

                //Setup data binding 
                this.column2DataGridViewComboBox.DataSource = dataSource;
                this.column2DataGridViewComboBox.DisplayMember = "Unit";

                break;

                case 1:

                //Build a list 
                dataSource.Add(new Units() { Unit = "blah4" });
                dataSource.Add(new Units() { Unit = "blah5" });
                dataSource.Add(new Units() { Unit = "blah6" });

                //Setup data binding 
                this.column2DataGridViewComboBox.DataSource = dataSource;
                this.column2DataGridViewComboBox.DisplayMember = "Unit";

                break;

                case 2:

                //Build a list 
                dataSource.Add(new Units() { Unit = "blah7" });
                dataSource.Add(new Units() { Unit = "blah8" });
                dataSource.Add(new Units() { Unit = "blah9" });

                //Setup data binding 
                this.column2DataGridViewComboBox.DataSource = dataSource;
                this.column2DataGridViewComboBox.DisplayMember = "Unit";

                break;

            }
        }



        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            ComboBox cb;


            Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "EditControlShowing");
            switch (dataGridView1.CurrentCell.ColumnIndex)
            {
                case 0:
                    
                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;
            }
        }


I'm still working on it, but let me show you what debug.writeline is outputting in a couple of cases:

Selecting the drop down for column 1 comboxBox (let's call it cb1) gives:

0EditControlShowing, that is expected. Smile | :)

Selecting index 1 in cb1 gives:

0SelectedIndexChanged, good....

Selecting the drop down for column 2 combox (cb2) gives:

0SelectedIndexChanged
0SelectedIndexChanged

Then selecting index 1 for cb2 gives:

1EditControlShowing
0SelectedIndexChanged
0SelectedIndexChanged

Somehow I need to keep ComboBox cb in SelectedIndexChanged from hooking up with the comboBox in column2...

I'll keep scratching my head..... Cry | :((

modified on Thursday, May 20, 2010 10:02 AM

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 
GeneralRe: Outlook 2007 - Editing calendar information Pin
lvq68418-May-10 7:43
lvq68418-May-10 7:43 

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.