Question Set Focus

virgel

New member
Joined
Mar 23, 2010
Messages
2
Programming Experience
Beginner
Hello! Good Day Guys! I want to seek some help out there, i hope you can help me with this little problem of mine in vb.net. I created a test project and i got stuck with this problem on how to code this, I have a tabcontrol in the form with two tabpages. In every tabpages, i have a datagridview (datagridview1 in tabpages1 and datagrdiview2 in tabpages2). My problem is this, in tabpages1 i set the focus to datagridview1 which belong to tabpages1 and if i click the tabpages2 i want to still remain the focus set to datagridview1. How can i do this in code programmatically? In my current situation, when i click the tabpages2 i lost the focus in datagridview1 which in tabpages1.. Your reply is really appreciated guys... thanks.
 
I didn't understand why you need to have focus on first datagrid when you choose second tab. Choosing second tab will display the controls in second tab. If you want that when tab displayed the focus is set to datagrid then you should set focus to datagrid in tabcontrol selected event like this...

Private Sub TabControl1_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControl1.Selected
If TabControl1.SelectedIndex = 0 Then
datagridview1.focus()
Else
datagridview2.focus()
End If

End Sub
 
Back
Top