update tabcontrol tab

1

I am creating a program in Windows Forms and on my page I put a Tab Control with one tab to register and insert the data in MySQL and the other to see the data registered in a ComboBox. p>

But when I insert one data from the registration tab and mute it to the other, my ComboBox does not have the data entered, then I have to close the program and open it again to appear in the ComboBox.

How do I when I insert into a flap it recognizes the other?

    
asked by anonymous 08.06.2017 / 16:40

1 answer

2

This is exactly the expected behavior. Once you load ComboBox , you'll need to load the data back into it when you make new inserts.

There are several ways to handle this: you can update when adding an item, you can update when you change the tab and so on.

I advise you to reload the combo whenever the user switches from the first tab to the second.

To do this, you must use the Selecting " of TabControl . Note: Do not forget to inscribe the event in the component.

The code would be more or less this

void tabControl_Selecting(object sender, TabControlCancelEventArgs e)
{
     TabPage tabPageSelecionada = (sender as TabControl).SelectedTab;

     //troque tabPageConsulta pelo "Name" previamente definido para a tab page
     if(tabPageSelecionada == tabPageConsulta)  
     {
         //Buscar os dados no banco e recarregar a combobox
     }
}
    
08.06.2017 / 16:50