Link to home
Start Free TrialLog in
Avatar of thefunnydad
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.
Avatar of angelfeijoo
angelfeijoo

Hi,

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
Avatar of thefunnydad

ASKER

That did not work.....

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        Dim sn As String
        sn = TreeView1.SelectedNode.Text
        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()
ActiveControl = txtFacilityID doesn't work either.

The ACTUAL call stackat the End Sub for the AfterSelect event of the Tree......

>      ssi.exe!ssi.frmMain.TreeView1_AfterSelect(Object sender = {System.Windows.Forms.TreeView}, System.Windows.Forms.TreeViewEventArgs e = {System.Windows.Forms.TreeViewEventArgs}) Line 3641      Basic
       [<Non-user Code>]      
       ssi.exe!ssi.frmMain.Main() Line 1 + 0x1d bytes      Basic

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
Avatar of S-Twilley
S-Twilley

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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).


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