I have a TabControl with three tabs in it. Each tab contains a DataGridView. When I display the TabControl for the first time, I databind my source data to each of the three DataGridViews and after some delay, the TabControl appears on the screen on the default (1st) tab.
When I click on either of the other two tabs (for the first time only), there is a very lengthy delay before each tab is shown. Once any of the tabs has been displayed at least once, I can freely switch between tabs very quickly. Is there any way that I can pre-load or pre-render these tabs so that I don't experience this delay on the first display?
Perhaps I can do something in a thread in the background to pre-load the remaining tabs. Or perhaps someone has written an extension of the TabControl which does this for me.
Any help is appreciated.
Edit: As requested by krawl, here is the code I am using that binds the data to the DataGridViews.
public void LoadNewDataBase(string filename)
{
// Create the database connection
mySQL.CreateNewDataBase(filename);
// Display the DF DataSet
dataGridViewDF.DataSource = GetDataSet("DF").Tables[0].DefaultView;
dataGridViewSA.DataSource = GetDataSet("SA").Tables[0].DefaultView;
dataGridViewGPS.DataSource = GetDataSet("GPS").Tables[0].DefaultView;
dataGridViewDF.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridViewSA.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridViewGPS.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
// Preload the tabs
for (int i = tabControl1.TabCount - 1; i >= 0; i--)
{
tabControl1.SelectedIndex = i;
tabControl1.Invalidate();
tabControl1.Update();
}
}
private DataSet GetDataSet(string tableName)
{
DataSet ds = new DataSet();
mySQL.GetDataSet("SELECT * FROM " + tableName).Fill(ds);
return ds;
}
This operation is not threaded. As a temporary solution to my problem, I included that for loop into my LoadNewDataBase method for iterating over each tab and displaying it. To obfuscate this operation from the user, I overlay a graphic on top of my TabControl to indicate that the control is loading and then I hide it afterwards (code for that not included). It's useful as a workaround but not an elegant solution.