Tree view problem

O

Omar Abid

Hi,
I'm using a tree view to manage my tables.
The nodes are made dynamiclly, the problem that I want to create an
event when I select a node. I used the code below
treeview.selectednode.index = 0
but when I use that code the event run on all nodes and children nodes
I want to associate an index to each node to resolve that problem
Does any one had solution
Omar Abid
 
P

Phillip Ross Taylor

Hi,
I'm using a tree view to manage my tables.
The nodes are made dynamiclly, the problem that I want to create an
event when I select a node. I used the code below
treeview.selectednode.index = 0
but when I use that code the event run on all nodes and children nodes
I want to associate an index to each node to resolve that problem
Does any one had solution
Omar Abid

When a user clicks / selects a node the "AfterSelect" event fires. You
can then probe tree1.selectednodes to see what exactly was selected.

You can also create an OnMouseDown event for the tree and add the
line:

treMain.SelectedNode = treMain.GetNodeAt(e.X, e.Y)

And finally there is an event called "NodeMouseClick" which you can
use to signal something has been clicked and take the appropriate
action.

But it's hard for me to understand what your trying to do.
 
O

Omar Abid

When a user clicks / selects a node the "AfterSelect" event fires. You
can then probe tree1.selectednodes to see what exactly was selected.

You can also create an OnMouseDown event for the tree and add the
line:

treMain.SelectedNode = treMain.GetNodeAt(e.X, e.Y)

And finally there is an event called "NodeMouseClick" which you can
use to signal something has been clicked and take the appropriate
action.

But it's hard for me to understand what your trying to do.

The problem is the node. I want to attribute to each note an index so
i can add to each node a special event
How to do that ?
 
P

Phill W.

Omar said:
The problem is the node. I want to attribute to each node an index so
i can add to each node a special event

Why bother?

Derive your own TreeNode class and add instances of this to the TreeView.
In the Tree's AfterSelect event, test the Type of the node that was
clicked on and, if it's one of yours, invoke the required method.

Class CustomNode
Inherits TreeNode

Private Sub New()
End Sub

Public Sub New( ByVal sText As String )
MyBase.Text = sText
End Sub

Public Sub DoSomething()
End Sub

End Class

Dim node As New CustomNode( "Fred" )
treMain.Add(node)

Sub treMain_AfterSelect( ... ) _
Handles treMain.AfterSelect

If TypeOf e.Node Is CustomNode Then
With DirectCast(e.Node, CustomNode)
.DoSomething()
End With
End If

End Sub

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top