Results 1 to 4 of 4

Thread: [2005] Change focus after mouseclick on treeview

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    268

    [2005] Change focus after mouseclick on treeview

    I have a treeview, and lets say in the treeview I have the nodes "Textbox1", "Textbox2", and "Textbox3". Also on the form I have 3 textboxes. What I want it to do is when I click "Textbox1" in the tree, to select all text and bring focus to the first textbox. So on the AfterSelect event of the treeview, I find out what node Im on, and what textbox to go to, then I say Textbox1.Focus() : Textbox1.SelectAll().

    When I use the keyboard and navigate to that node, it works. It jumps the focus off of the treeview and to that textbox, selecting all it's text. Works fine.
    But when I click on it with my mouse, it doesn't. It does select the text, bring focus to the textbox, but immediately brings focus right back to the treeview. (you have to look really close to see it) I'm thinking there's some mouse event that is bringing the focus back to the treeview, but not sure what.
    Any ideas?
    Thanks.

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] Change focus after mouseclick on treeview

    I tend to use the NodeMouseClick event instead of the AfterSelect event for this very reason..
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Change focus after mouseclick on treeview

    Quote Originally Posted by chris128
    I tend to use the NodeMouseClick event instead of the AfterSelect event for this very reason..
    You'd probably have to handle both, or else it won't work for keyboard navigation.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    268

    Re: [2005] Change focus after mouseclick on treeview

    Still doesn't work even when handling it under NodeMouseClick.

    Something wierd I did notice though, If I click on the node, and it's supposed to bring focus to TextBox1 but instead brings it back to the treeview. However, once I click in the treeview not on a node, it switches the focus to the Textbox. Here's my code:

    vb.net Code:
    1. Private Sub tvwMain_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvwMain.NodeMouseClick
    2.         If Not tvwMain.SelectedNode Is Nothing Then
    3.             Select Case tvwMain.SelectedNode.Level
    4.                 Case 1
    5.                     Select Case tvwMain.SelectedNode.Text
    6.                         Case "Business Information" : Call cParent_Main.Load()
    7.                         Case "Contact Information" : Call cParent_Contact.Load()
    8.                         Case "Account Information" : Call cParent_Accounts.Load()
    9.                     End Select
    10.                 Case 2
    11.                     Select Case tvwMain.SelectedNode.Parent.Text
    12.                         Case "Business Information"
    13.                             If Not TypeOf CurrentPage Is Parent_Main Then Call cParent_Main.Load()
    14.                             Select Case tvwMain.SelectedNode.Tag
    15.                                 Case "DBA"
    16.                                     CType(CurrentPage, Parent_Main).txtDBA.Focus()
    17.                                     CType(CurrentPage, Parent_Main).txtDBA.SelectAll()
    18.                                 Case "Name"
    19.                                     CType(CurrentPage, Parent_Main).txtCompanyName.Focus()
    20.                                     CType(CurrentPage, Parent_Main).txtCompanyName.SelectAll()
    21.                                 Case "Category"
    22.                                     CType(CurrentPage, Parent_Main).cboCategory.Focus()
    23.                                     CType(CurrentPage, Parent_Main).cboCategory.SelectAll()
    24.                                 Case "Num"
    25.                                     CType(CurrentPage, Parent_Main).txtNum.Focus()
    26.                                     CType(CurrentPage, Parent_Main).txtNum.SelectAll()
    27.                                 Case "PayableTo"
    28.                                     CType(CurrentPage, Parent_Main).txtPayableTo.Focus()
    29.                                     CType(CurrentPage, Parent_Main).txtPayableTo.SelectAll()
    30.                                 Case "SSN"
    31.                                     CType(CurrentPage, Parent_Main).txtSSN.Focus()
    32.                                     CType(CurrentPage, Parent_Main).txtSSN.SelectAll()
    33.                                 Case "TaxID"
    34.                                     CType(CurrentPage, Parent_Main).txtTaxID.Focus()
    35.                                     CType(CurrentPage, Parent_Main).txtTaxID.SelectAll()
    36.                             End Select
    37.                     End Select
    38.             End Select
    39.         End If
    40.     End Sub

    In the above code, "Parent_Main" is a user control, and "cParent_Main" is a class handling the functions for that user control.


    Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width