Ok I solved it.
The issue is when you start your program you have to view each tab.
Any tab you have viewed will now populate.

Adding...  

tabControl1.SelectedIndex = 1;
tabControl1.TabPages[1].Parent.Select();

tabControl1.SelectedIndex = 0;
tabControl1.TabPages[0].Parent.Select(); 


...to the Form Load event solved the issue for me.

It happens too fast to see, but gets the job done.

Greg



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Greg Hile
Sent: Monday, August 30, 2010 12:34 PM
To: [email protected]
Subject: [DotNetDevelopment] Strange ComboBox issue

I am having the strangest issue using C# and VS 2008 Pro

I have a Windows Forms application with a tab control with two tabs.

        List<string> DataA = new List<string> { "", "A", "B", "C", "D" };
      List<string> DataB = new List<string> { "", "E", "F", "G", "H" };

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = DataA;
            comboBox2.DataSource = DataB;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            comboBox1.Text = "Test1";
            comboBox2.Text = "test2";
        }

Pretty straightforward. 

Now if I put both comboboxes in the first TabPage when I click button1 it
fills in the text even though it is not on the list of it's datasource.
That is fine with me, I want it that way.

Now, if I move either combobox to the second tabpage then its text will not
get populated UNLESS it matches a string from the datasource.

So while Combo1 and Combo2 will both end up with "Test1" and "Test2", if I
move ComboBox2 to the 2nd tabpage then Combo2.Text will not be populated.
If I change the code to say 
        
        comboBox2.Text = "F";

then it will populate.

Anybody have any ideas?

Greg



 




Reply via email to