Created On:  14 January 2013


Customer has a Visual COBOL Windows Forms application that has forms which use TabControls made up of various tabPages. Each tabPage contains data relevant to the header.

The first tabPage on form XYZ is called 'Personal'. The first textBox control on tabPage 'Personal' is called 'Per-Code'.

The tab order says that 'Per-Code' is value 0.0.0 with the Personal tabPage having a tab order of 0. There are no other tab values of 0.0.0 within the tabPage of Personal.

At runtime the code used is within the Form_Load event is:

     set tabControl1::SelectedTab to Personal
     Invoke Per-Code::Focus 

However, on running the form the field Per-Code doesn't become active until the key is pressed and then the textBox Per-Code becomes 'live' and editable.

What command needs to be used so that the key does not have to be pressed first in order to make the Per-Code textBox active?


There are two possible solutions to set the focus to a control on a specific tabPage within a tabControl.

1.  Try putting the code in the Form_Shown event instead of in New or Form_Load.

     It does not work in New or Load events because after load, the controls are re-focused according to tab order and the focused control is "overwritten".  
     When you focus the control in Shown, there is nothing that would "overwrite" your call by focusing another control.

2.  Use the following code instead within New or Load event:

     set tabControl1::SelectedTab to Personal
     set self::ActiveControl to Per-Code

Incident #2609069