Focus not setting on text box
I have a sub that goes off when a tab selection is changed. The only part of it that doesn't seem to work right is the part that sets the focus on the text box. It seem to be a trivial thing to do but I can't seem to get it to work. I have other focus objects which work in other places but this one doesn't seem to want to work. I know the Text boxes are correct and do not get any errors. I have walked though the code in debug mode and and it steps through the lines one by one. It even executes the Focus line but returns false for a value. Anyone have an idea why?Here is the code:
Private
Sub TabControl_Selected(ByVal senderAs System.Object,ByVal eAs System.Windows.Forms.TabControlEventArgs)Handles TabControl.Selected If (e.TabPageIndex() <> 0And UserID.Text ="")Then ScanTab.Enabled =
False
TransferTab.Enabled =False
TransmitTab.Enabled =False Else ScanTab.Enabled =
True
TransferTab.Enabled =True
TransmitTab.Enabled =True EndIf If (e.TabPageIndex() = 0)Then UserID.Focus()
EndIf If (e.TabPageIndex() = 1)Then Barcodetext.Focus()
EndIfEndSub
[3216 byte] By [
guinea13] at [2007-12-16]
Hi,
Try placing your code in the SelectedIndexChanged event of the tabcontrol. I just tried it and it works fine...
cheers,
Paul June A. Domag
If I try to create a TabControl_SelectedIndexChanged event it automatically creates it with System.EventArgs like:
Private Sub tabGymPass_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabGymPass.SelectedIndexChanged
End Sub
I can't manually change it to System.Windows.Forms.TabControlEventArgs like:
Private Sub tabGymPass_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlControlEventArgs) Handles tabGymPass.SelectedIndexChanged
If (e.TabPageIndex = 0) Then
txtFindID.Focus()
End If End Sub
or I get the following error:
Error 1 Method 'Private Sub tabGymPass_SelectedIndexChanged(sender As Object, e As System.Windows.Forms.TabControlCancelEventArgs)' cannot handle Event 'Public Event SelectedIndexChanged(sender As Object, e As System.EventArgs)' because they do not have the same signature. C:\Documents and Settings\chas\My Documents\Visual Studio 2005\Projects\MyGymPass\MyGymPass\Form1.vb 54 151 MyGymPass
What am I doing wrong?
You can't change it, but you don't actually need those special e parameters because the 'sender' object is the TabControl that caused the event, so you can retrieve the currently selected tabpage(-index) from that:
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
Dim zSendertabControl As TabControl = sender
Dim zCurrentSelectedIndex As Integer = zSendertabControl.SelectedIndex
End Sub