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

C#

 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 17:29
mprice21418-May-10 17:29 
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 
Guess who.

I have the following:

private void column1DataGridViewComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

            ComboBox cb = sender as ComboBox;

         
            string strPrimary = cb.SelectedItem.ToString();
            Debug.WriteLine(strPrimary);

            var dataSource = new List<Units>();

            switch (strPrimary)
            {
                case "1":
                    
                //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 "2":

                //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 "3":

                //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;

            }
        }<pre>

Well, the problem of course as you know is that ComboBox cb points to the second comboBox once I select it.  In fact, once I select a value on the first comboBox and then select the second comboBox to select a value, debug.writeline gives me "WindowsFormsApplication1.Form1+Units" (although the 2nd comboBox does get populated with the appropriate list based upon the selection of the first comboBox).  If I use an integer instead of strPrimary and set it as cb.SelectedIndex, what I actually get from debug is the index of the selection of the list of the second comboBox (eg if blah5 is selected, I get an integer = 1) followed by an integer = 0 (I don't know why it is passing that second integer = 0  ??), which then causes the list to be regenerated to the items in case 0.  Since ComboBox cb points to the second comboBox, and it passes that second integer = 0, the only allowable entry into the second comboBox would be "blah1"

With all of this, it seems that either close or going about it all wrong, but I don't know enough to make that call.  I know that the control for each comboBox needs to be separated, but don't have the slightest notion how to do that.  You had mentioned that in a previous post, but in the EditingControlShowing handler.  As usual, any suggestions would be greatly appreciated.

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 
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 

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.