Change dropdown text on another tab

I have a combo box that I need to display on another tab in a winforms based application in C #.

I have great working code when you select another item from the drop down list. Unfortunately, however, when I change the Texttabs on which the button was not pressed, nothing happens.

If I click each tab first, then everything will work as expected.

Now I put this in some form of lack of initialization that happens first. So I tried to select each tab in my constructor.

tabControlDataSource.SelectedIndex = 0;
tabControlDataSource.SelectedIndex = 1;
// etc

But that will not work.

I also tried calling tabControlDataSource.SelectTab( 1 ), but it still doesn't work.

Does anyone know how I can make the tab “initialize”?

+5
source share
2 answers

Well, as a rule, I post a question after the battle for an hour and soon after that I find a solution.

Tablets are initialized lazily. Therefore, they are not fully initialized until they become visible for the first time.

So, I added this code to my constructor:

        tabControlDataSource.TabPages[0].Show();
        tabControlDataSource.TabPages[1].Show();
        tabControlDataSource.TabPages[2].Show();

but this did not work :(

However, it occurred to me that the designer might not be the best place. So I created an event handler for Shownas follows:

    private void MainForm_Shown( object sender, EventArgs e )
    {
        tabControlDataSource.TabPages[0].Show();
        tabControlDataSource.TabPages[1].Show();
        tabControlDataSource.TabPages[2].Show();
    }

And now everything works!

+3
source

, "" (). : ( , ), ( combobox , , , comboboxes ..), " ", ( )...

, = D

+2

All Articles