?
Solved

vb.net setting focus

Posted on 2005-04-18
9
Medium Priority
?
877 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:thefunnydad
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:angelfeijoo
ID: 13806658
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
0
 

Author Comment

by:thefunnydad
ID: 13806768
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()

0
 
LVL 14

Expert Comment

by:amyhxu
ID: 13807033
Try Me.ActiveControl = txtFacilityID instead of txtFacilityID.Focus()
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:thefunnydad
ID: 13807193
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

0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13807211
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)
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13807290
Click event isn't much help either, if you click on a new node, the selectednode property points to the previously selectednode
0
 
LVL 12

Accepted Solution

by:
S-Twilley earned 2000 total points
ID: 13807424

   ' CAPTURES WHEN YOU SELECT THE NODE VIA THE CURSOR KEYS
    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        If e.Action = TreeViewAction.ByKeyboard And e.Node.Text = "test1" Then
            Me.ActiveControl = Me.txtMisc
        End If
    End Sub

    ' CAPTURES WHEN THE CONTROL GETS THE FOCUS... AND THE NODE LAST SELECTED WAS THE NODE IN QUESTION
    Private Sub TreeView1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.GotFocus
        If Not TreeView1.SelectedNode Is Nothing Then
            If TreeView1.SelectedNode.Text = "test1" Then
                Me.ActiveControl = Me.txtMisc
            End If
        End If
    End Sub

     'CAPTURES WHEN THE LEFT MOUSE BUTTON IS PRESSED ON THE QUESTIONED NODE
    Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
        If e.Button = MouseButtons.Left Then
            Dim hitNode As TreeNode = TreeView1.GetNodeAt(e.X, e.Y)

            If Not hitNode Is Nothing Then
                If hitNode.Text = "test1" Then
                    Me.ActiveControl = Me.txtMisc
                End If
            End If
        End If
    End Sub

========

All needs more testing, but seems to work on a simple structure of nodes
0
 
LVL 3

Expert Comment

by:angelfeijoo
ID: 13807625
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).


0
 

Author Comment

by:thefunnydad
ID: 13807962
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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question