Reputation: 383
I'm trying to make a help file in Visual Basic. I've decided to go the route of replicating the old style help files with a TreeView
panel, to the left, and a RichTextbox
, on the right, of the form. (This set-up looks like the help file in PowerShell almost exactly.
I'm trying to make it so that when a TreeView
Node
is Single Clicked
the RichTextbox
Text
will change to the appropriate text. Here is my code:
Private Sub treeView_NodeMouseClick(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles TreeViewContents.NodeMouseClick
If e.Node.Text.Equals("Program Help") Then
RTBHelp.Text = Environment.NewLine & "Help text here."
End If
If e.Node.Text.Equals("Program Getting Started") Then
RTBHelp.Text = Environment.NewLine & "Getting Started text here"
End If
End Sub
The problem is that the text will change when simply clicking the Plus
or Minus
located next to the TreeView
Node
. But, I want to emulate the PowerShell help behavior, where clicking the Plus
or Minus
expands or collapses the nodes but does not change the RichTextbox
Text
. Only when clicking on the Nodes
name (Text
) itself should the RichTextbox
Text
change. I have tried several methods but none seem to work. What do I do?
Upvotes: 0
Views: 7160
Reputation: 13
This might be too late but i just had same problem. I used the AfterSelect Event. It is logically that NodeClick Event is fired when one tries to expand the node since we are clicking on the Node by expanding it. If one is interested on just the Selection done by the mouse then it is necessary to check if e.Action = TreeViewAction.ByMouse.
Private Sub treeView_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeView.AfterSelect
If e.Action = TreeViewAction.ByMouse Then
If e.Node.Text.Equals("Program Help") Then
RTBHelp.Text = Environment.NewLine & "Help text here."
End If
If e.Node.Text.Equals("Program Getting Started") Then
RTBHelp.Text = Environment.NewLine & "Getting Started text here"
End If
End If
End Sub
By using "if TreeViewAction.ByMouse then ...", the code under the if Statement will be excuted if one presses the arrow-keys or the mouse. So the first If Statement is very important if only the mouse selection is to be caught.
Upvotes: 1