Quick and dirty, the important thing is the directcast in the afterselect
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
_ Handles MyBase.Load
TreeView1.Nodes .Add(New MyTreeNode("Bel gium", "BE"))
TreeView1.Nodes .Add(New MyTreeNode("Net herlands", "NL"))
TreeView1.Nodes .Add(New MyTreeNode("Fra nce", "FR"))
TreeView1.Nodes .Add(New MyTreeNode("Ger many", "GER"))
End Sub
Private Sub TreeView1_After Select(ByVal sender As Object, ByVal e As _
System.Windows. Forms.TreeViewE ventArgs) Handles TreeView1.After Select
MsgBox(DirectCa st(TreeView1.Se lectedNode, MyTreeNode).val ue)
End Sub
Public Class MyTreeNode
Inherits TreeNode
Private myvalue As String
Public Property value() As String
Get
Return myvalue
End Get
Set(ByVal Value As String)
myvalue = Value
End Set
End Property
Sub New(ByVal text As String, ByVal value As String)
MyBase.New()
Me.Text = text
Me.value = value
End Sub
End Class
hth Greetz Peter
"Samuel R. Neff" <bl****@newsgro up.nospam> wrote in message
news:ch******** *************** *********@4ax.c om...
You can cast it.
DirectCast(e.No de, MyCustomTreeNod e).Value
btw, perhaps you use the Tag property instead of a custom class?
HTH,
Sam
On 26 Jan 2005 07:38:21 -0800, "johnb41" <or****@informa tik.com>
wrote:
In my treeview, I need each node to hold a "value", not just
text/label. Kind of like how a ListBox item has text, and a value
associated with it. I need this because when a node is clicked, i need
to get the "value" behind the node and then use it do do something.
Anyway, I made a custom treenode class that inherits from Treenode, and
added a property called "value".
I was able to successfully create the Treeview programmaticall y from a
database, which includes the "value" property that i made.
Here's my problem: The routine I have to run when a user clicks a node
is this:
Private Sub treeview_AfterS elect(ByVal sender As System.Object,
ByVal e As System.Windows. Forms.TreeViewE ventArgs) Handles
treeview.After Select
'do something with e.Node.value
End Sub
Because my "value" property was added in my custom class, it is not
available to use in TreeViewEventAr gs. So e.Node.Value will not work.
How can I do this?...i'm stumped!
Thanks for your help!
John