thefunnydad
asked on
vb.net setting focus
I have a form with a tree view and several frames. All groupboxes are invisible. User clicks on a node in the tree, making the corresponding groupbox visible. I want to set the focus, ie cursor, to a particular texbox in the groupbox, but it won't stick. All the work is being done under the AfterSelect in the Tree; I'm making the last statement textbox.focus(), but it isn't sticking.
ASKER
That did not work.....
Private Sub TreeView1_AfterSelect(ByVa l sender As System.Object, ByVal e As System.Windows.Forms.TreeV iewEventAr gs) Handles TreeView1.AfterSelect
Dim sn As String
sn = TreeView1.SelectedNode.Tex t
Select Case sn
Case "New Claim"
gbImport834.Visible = False
gbSearch.Visible = False
gbdemo.Visible = False
gbEmp.Visible = False
gb1500.Visible = True
gbDb.Visible = False
gb1500.Refresh()
txtFacilityID.Focus()
End Select
C&P of the Call Stack to show nowhere to return to that I know of, and after this End Select, we End Sub, no more work to be done..... Curson still no in the textbox.
txtFacilityID.Focus()
Private Sub TreeView1_AfterSelect(ByVa
Dim sn As String
sn = TreeView1.SelectedNode.Tex
Select Case sn
Case "New Claim"
gbImport834.Visible = False
gbSearch.Visible = False
gbdemo.Visible = False
gbEmp.Visible = False
gb1500.Visible = True
gbDb.Visible = False
gb1500.Refresh()
txtFacilityID.Focus()
End Select
C&P of the Call Stack to show nowhere to return to that I know of, and after this End Select, we End Sub, no more work to be done..... Curson still no in the textbox.
txtFacilityID.Focus()
Try Me.ActiveControl = txtFacilityID instead of txtFacilityID.Focus()
ASKER
ActiveControl = txtFacilityID doesn't work either.
The ACTUAL call stackat the End Sub for the AfterSelect event of the Tree......
> ssi.exe!ssi.frmMain.TreeVi ew1_AfterS elect(Obje ct sender = {System.Windows.Forms.Tree View}, System.Windows.Forms.TreeV iewEventAr gs e = {System.Windows.Forms.Tree ViewEventA rgs}) Line 3641 Basic
[<Non-user Code>]
ssi.exe!ssi.frmMain.Main() Line 1 + 0x1d bytes Basic
The ACTUAL call stackat the End Sub for the AfterSelect event of the Tree......
> ssi.exe!ssi.frmMain.TreeVi
[<Non-user Code>]
ssi.exe!ssi.frmMain.Main()
Just tested that, only seems to work with keyboard events (least for me)... think you need to add handlers for TreeView.Click (check for SelectedNode.Text)... and also TreeView.GotFocus (again, check the SelectedNode property of the treeview)
Click event isn't much help either, if you click on a new node, the selectednode property points to the previously selectednode
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A non-elegant solution:
If you have a label before that txtFacilityID, like "lblFacilityID", set their TabIndex properties to be consecutive numbers and do:
'...
gb1500.Visible = True
SendKeys.Send ("%F")
End Select
Assuming that your label has a text like "&Facility". (change the sendkeys to send the underlined letter of your label).
If you have a label before that txtFacilityID, like "lblFacilityID", set their TabIndex properties to be consecutive numbers and do:
'...
gb1500.Visible = True
SendKeys.Send ("%F")
End Select
Assuming that your label has a text like "&Facility". (change the sendkeys to send the underlined letter of your label).
ASKER
Steven,
I C&P your middle suggestion right into my form and it worked like a charm. Much thanks, it was drving me nuts. I know dotnet is supposed to be superior, but it sure seemed easier in VB5/6.....
thanks to all who cotributed.
Scott
I C&P your middle suggestion right into my form and it worked like a charm. Much thanks, it was drving me nuts. I know dotnet is supposed to be superior, but it sure seemed easier in VB5/6.....
thanks to all who cotributed.
Scott
Try groupbox.Refresh after you make it visible and before you give focus to the TextBox.
If that doesn't work please provide some code to better understand the issue.
Angel