0

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 Textchange. I have tried several methods but none seem to work. What do I do?

user2348797
  • 353
  • 4
  • 9
  • 21

2 Answers2

1

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.

0

Use the AfterSelect event instead.

DBNickel
  • 61
  • 1
  • The code handles this event nearly exactly the same as on click. I can add some `If Statements` to modify the behavior, but it only gives a half fix (with `TreeViewContents.AfterSelect` and `If e.Node.IsExapanded And Also e.Node.Text.Equals("Program Help")` This stops the text from changing when a nodes minus box is clicked but it also force the user to have to expand a node, click a child node, then the parent node to change the text of a parent node on after expansion. – user2348797 May 22 '13 at 05:22