שתף באמצעות


How to get the key string of a selected node on vb.net?

Question

Wednesday, November 4, 2009 5:19 AM

I am trying to get the Key string of a selected node on the TreeView; I know how to get index, name, imagekey, etc... But I am having a hard time getting the Key string.

Thank You.

All replies (2)

Wednesday, November 4, 2009 5:35 AM ✅Answered | 1 vote

The documentation says this:

"The Name property corresponds to the key for a TreeNode in the TreeNodeCollection."

So if you are getting the name, you are already getting the key.

This is the code I tried:

        Dim tv As New TreeView
        tv.Nodes.Add("Key1", "Apple")
        tv.Nodes.Add("Key2", "Banana")
        Me.Controls.Add(tv)
        For Each n As TreeNode In tv.Nodes
            Debug.WriteLine(n.Name)
        Next

Hope this helps.www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!


Wednesday, November 4, 2009 2:35 PM

DeborahK,

That is perfect thank you.