Retrieving data into DataWindow controls on tab pages

Controls on a tab page are not created until the tab page displays, so you cannot set the Transaction object and retrieve data into a DataWindow control on a hidden tab page until the tab page displays. There are two ways to retrieve data into DataWindowControls on hidden tab pages:


Using the SelectedIndexChanged event of the TabControl

The SelectedIndexChanged event of the TabControl is fired when the 0-based index of the currently-selected tab page changes. In the handler for this event, you can check whether the second and subsequent tab pages have been displayed, and, if they have not, set the Transacation object for the DataWindow control on that tab page and retrieve data.

The following C# example has three tab pages. Setting the value of the boolean variables _tab2FirstShown and _tab3FirstShown to true allows you to check whether the tab page is being displayed for the first time. No special handling is needed for the first tab page, because the controls are instantiated when the tab control first displays.

bool _tab2FirstShown = true;
bool _tab3FirstShown = true; 
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)

{
   if (this.tabControl1.SelectedIndex == 1 &&
      _tab2FirstShown)
   {
      _tab2FirstShown = false;
      dataWindowControl2.SetTransaction(transaction1);
      dataWindowControl2.Retrieve();
   }

   else if (this.tabControl1.SelectedIndex == 2 &&
      _tab3FirstShown)
   {
      _tab3FirstShown = false;
      dataWindowControl3.SetTransaction(transaction1);
      dataWindowControl3.Retrieve();
   }
}

Using the DataWindowCreated event of the DataWindowControl

You can also set the Transactation object for the DataWindow control and retrieve data in the DataWindowCreated event for each DataWindowControl on a tab page that is hidden when the TabControl first displays:

private void dw_2Created(object sender, Sybase.DataWindow.DataWindowCreatedEventArgs e)

{
   dataWindowControl2.SetTransaction(transaction1);
   dataWindowControl2.Retrieve();
}

private void dw_3Created(object sender, Sybase.DataWindow.DataWindowCreatedEventArgs e)

{
   dataWindowControl3.SetTransaction(transaction1);
   dataWindowControl3.Retrieve();
}