|
-
Jan 7th, 2009, 02:37 PM
#1
Thread Starter
Hyperactive Member
[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.
-
Jan 7th, 2009, 07:22 PM
#2
Re: [2005] Change focus after mouseclick on treeview
I tend to use the NodeMouseClick event instead of the AfterSelect event for this very reason..
-
Jan 7th, 2009, 07:51 PM
#3
Re: [2005] Change focus after mouseclick on treeview
 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.
-
Jan 8th, 2009, 10:33 AM
#4
Thread Starter
Hyperactive Member
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:
Private Sub tvwMain_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvwMain.NodeMouseClick
If Not tvwMain.SelectedNode Is Nothing Then
Select Case tvwMain.SelectedNode.Level
Case 1
Select Case tvwMain.SelectedNode.Text
Case "Business Information" : Call cParent_Main.Load()
Case "Contact Information" : Call cParent_Contact.Load()
Case "Account Information" : Call cParent_Accounts.Load()
End Select
Case 2
Select Case tvwMain.SelectedNode.Parent.Text
Case "Business Information"
If Not TypeOf CurrentPage Is Parent_Main Then Call cParent_Main.Load()
Select Case tvwMain.SelectedNode.Tag
Case "DBA"
CType(CurrentPage, Parent_Main).txtDBA.Focus()
CType(CurrentPage, Parent_Main).txtDBA.SelectAll()
Case "Name"
CType(CurrentPage, Parent_Main).txtCompanyName.Focus()
CType(CurrentPage, Parent_Main).txtCompanyName.SelectAll()
Case "Category"
CType(CurrentPage, Parent_Main).cboCategory.Focus()
CType(CurrentPage, Parent_Main).cboCategory.SelectAll()
Case "Num"
CType(CurrentPage, Parent_Main).txtNum.Focus()
CType(CurrentPage, Parent_Main).txtNum.SelectAll()
Case "PayableTo"
CType(CurrentPage, Parent_Main).txtPayableTo.Focus()
CType(CurrentPage, Parent_Main).txtPayableTo.SelectAll()
Case "SSN"
CType(CurrentPage, Parent_Main).txtSSN.Focus()
CType(CurrentPage, Parent_Main).txtSSN.SelectAll()
Case "TaxID"
CType(CurrentPage, Parent_Main).txtTaxID.Focus()
CType(CurrentPage, Parent_Main).txtTaxID.SelectAll()
End Select
End Select
End Select
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|