VB.NET TreeView Control

I'm trying to drop an item into a specfic node but it only works if I have a node selected. I want to be able to drop an item on any node I select. VB6 use hittest to identify, what does .net use? thanks

Comments

  • : I'm trying to drop an item into a specfic node but it only works if I have a node selected. I want to be able to drop an item on any node I select. VB6 use hittest to identify, what does .net use? thanks
    :

    This code should be similar to hittest. Rework itm to your benefits. This code assumes that a treeview control names TreeView1 is placed on the form.

    Private Sub Form1_Load( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load

    TreeView1.Nodes.Add("Test")

    End Sub

    Private Sub TreeView1_MouseDown( _
    ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles TreeView1.MouseDown

    Dim node As TreeNode = TreeView1.GetNodeAt(e.X, e.Y)

    ' If there is no node at the coordinates then the node will be nothing
    If Not node Is Nothing Then
    MessageBox.Show(TreeView1.Nodes(0).Text)
    End If

    End Sub

    Click on the node to see the message box pop-up ... clicking else-where causes no error.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion