update tab of tabcontrol

Asked

Viewed 242 times

1

I’m creating a program in Windows Forms and on my page I put a Tab Control with a tab to register and insert the data in Mysql and the other to see the data registered in a Combobox.

Only when I insert a data by the registration tab and switch to the other, my Combobox does not have the data entered, then I have to close the program and open again to appear in Combobox.

How do I when insert into a tab it recognize in the other?

  • Does the answer meet the request? Does it need something to be improved?

1 answer

2


This is exactly the expected behavior. Once loaded the ComboBox, you will need to upload the data to it again when you make new inserts.

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

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

For this, it is necessary to use the event Selecting of TabControl. Note: Don’t forget to register the event in the component.

The code would be something like that

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.