Home All Groups Group Topic Archive Search About

Can't set focus to controls on TabPage

Author
11 Apr 2005 3:05 PM
Paul Close
A new solution/project consisting of a single windows form with a tab
control, 3 tab pages and a text box on each tab page. I expected the
following to set focus to the text box on the selected tab page but it does
not.

   Private Sub TabControl1_SelectedIndexChanged(...etc
    Select Case TabControl1.SelectedIndex
      Case 0
        txtBox1.Focus()
      Case 1
        txtBox2.Focus()
      Case 2
        txtBox3.Focus()
    End Select
  End Sub

CanFocus is false for the tab page and the text box while in the sub.
TabControl1.SelectedTab = TabPage1 before txtBox1.Focus() doesn't help
either.

What am I missing?

Thanks

Author
11 Apr 2005 3:12 PM
Brian Henry
is this  code in your page load even by any chance? because it wont work
there


Show quoteHide quote
"Paul Close" <supp***@computerdoctor.com.au> wrote in message
news:O0KHtfqPFHA.1476@TK2MSFTNGP09.phx.gbl...
>A new solution/project consisting of a single windows form with a tab
>control, 3 tab pages and a text box on each tab page. I expected the
>following to set focus to the text box on the selected tab page but it does
>not.
>
>   Private Sub TabControl1_SelectedIndexChanged(...etc
>    Select Case TabControl1.SelectedIndex
>      Case 0
>        txtBox1.Focus()
>      Case 1
>        txtBox2.Focus()
>      Case 2
>        txtBox3.Focus()
>    End Select
>  End Sub
>
> CanFocus is false for the tab page and the text box while in the sub.
> TabControl1.SelectedTab = TabPage1 before txtBox1.Focus() doesn't help
> either.
>
> What am I missing?
>
> Thanks
>
Author
11 Apr 2005 3:21 PM
Paul Close
It's the tab control SelectedIndexChanged event handler. No other user
entered code in the project.

Show quoteHide quote
"Brian Henry" <brianiupmsdn@newsgroups.nospam> wrote in message
news:uo0EjjqPFHA.648@TK2MSFTNGP14.phx.gbl...
> is this  code in your page load even by any chance? because it wont work
> there
>
>
> "Paul Close" <supp***@computerdoctor.com.au> wrote in message
> news:O0KHtfqPFHA.1476@TK2MSFTNGP09.phx.gbl...
>>A new solution/project consisting of a single windows form with a tab
>>control, 3 tab pages and a text box on each tab page. I expected the
>>following to set focus to the text box on the selected tab page but it
>>does not.
>>
>>   Private Sub TabControl1_SelectedIndexChanged(...etc
>>    Select Case TabControl1.SelectedIndex
>>      Case 0
>>        txtBox1.Focus()
>>      Case 1
>>        txtBox2.Focus()
>>      Case 2
>>        txtBox3.Focus()
>>    End Select
>>  End Sub
>>
>> CanFocus is false for the tab page and the text box while in the sub.
>> TabControl1.SelectedTab = TabPage1 before txtBox1.Focus() doesn't help
>> either.
>>
>> What am I missing?
>>
>> Thanks
>>
>
>
Author
11 Apr 2005 4:43 PM
Paul Close
You were on the right track Brian. Thanks. The tab control
SelectedIndexChanged event fires before the first form Load event so nothing
can recieve focus.

Show quoteHide quote
"Paul Close" <supp***@computerdoctor.com.au> wrote in message
news:OiHQ1oqPFHA.3384@TK2MSFTNGP10.phx.gbl...
> It's the tab control SelectedIndexChanged event handler. No other user
> entered code in the project.
>
> "Brian Henry" <brianiupmsdn@newsgroups.nospam> wrote in message
> news:uo0EjjqPFHA.648@TK2MSFTNGP14.phx.gbl...
>> is this  code in your page load even by any chance? because it wont work
>> there
>>
>> "Paul Close" <supp***@computerdoctor.com.au> wrote in message
>> news:O0KHtfqPFHA.1476@TK2MSFTNGP09.phx.gbl...
>>>A new solution/project consisting of a single windows form with a tab
>>>control, 3 tab pages and a text box on each tab page. I expected the
>>>following to set focus to the text box on the selected tab page but it
>>>does not.
>>>
>>>   Private Sub TabControl1_SelectedIndexChanged(...etc
>>>    Select Case TabControl1.SelectedIndex
>>>      Case 0
>>>        txtBox1.Focus()
>>>      Case 1
>>>        txtBox2.Focus()
>>>      Case 2
>>>        txtBox3.Focus()
>>>    End Select
>>>  End Sub
>>>
>>> CanFocus is false for the tab page and the text box while in the sub.
>>> TabControl1.SelectedTab = TabPage1 before txtBox1.Focus() doesn't help
>>> either.
>>>
>>> What am I missing?
>>>
>>> Thanks
>>>
>>
>>
>
>