By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

VB6 TreeView Node "Key" property Equivalent in VB.NET

P: n/a
Hi There!

I'm using VB.NET to create a TreeView application and unfortunately I could
not find "Key" property in Node items of the TreeView.

We used to have "Key" property in TreeView node object in VB6.

What is the equivalent of "Key" property of TreeView node in VB.NET? Has the
property name "Key" has been changed to something else? Or VB.NET does not
support the "Key" property anymore? If so what are the alternatives?

What I need is I need to assign "Key" (which contains text and number) to
each node I add to the TreeView. So "Index" property won't help me. I need
something similar to "Key" property that is used to support in TreeView
Nodes of VB6.

Thanks all in advance!
Don
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
* "Don Wash" <do*@wash.com> scripsit:
I'm using VB.NET to create a TreeView application and unfortunately I could
not find "Key" property in Node items of the TreeView.


There is no direct replacement for this property. You can set up a
'Hashtable' and store your (key, 'TreeNode') pairs for fast lookup by a
key there.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
lol seems I'm not the only one with problems...
I'm looking into your solution as we speak.

André Nogueira

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
* "Don Wash" <do*@wash.com> scripsit:
I'm using VB.NET to create a TreeView application and unfortunately I
could
not find "Key" property in Node items of the TreeView.


There is no direct replacement for this property. You can set up a
'Hashtable' and store your (key, 'TreeNode') pairs for fast lookup by a
key there.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
Thanks, I've tried HashTable method but it doesn't seems to work.

Here's the code...

With objNewNode
htMain.Add(strNodeKey, .Index)
htMain_IndexToKey.Add(.Index, strNodeKey)

.Text = "Node Item " & i
.ImageIndex = 1
End With

.Nodes.Add(objNewNode)

htMain and htMain_IndexToKey are HashTable objects. What happens is that
Index of objNewNode is always '0' (Zero).

So I though objNewNode is an independent TreeView Node which hasn't been
associated with the real TreeView control and I tried this code instead...

Dim intNodeIndex as Integer = .Nodes.Add(objNewNode)

htMain.Add(strNodeKey, intNodeIndex )
htMain_IndexToKey.Add(intNodeIndex , strNodeKey)

and still intNodeIndex equal '0' every time. How can I get the actual Node's
index currently being added to the TreeView Nodes collection?

Thanks again!

Don

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
* "Don Wash" <do*@wash.com> scripsit:
I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView.


There is no direct replacement for this property. You can set up a
'Hashtable' and store your (key, 'TreeNode') pairs for fast lookup by a
key there.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

P: n/a
Hi André,

How are you getting at? Did you get it to work?

Cheers,
Don

"André Nogueira" <an**@netcabo.pt.NOSPAM> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
lol seems I'm not the only one with problems...
I'm looking into your solution as we speak.

André Nogueira

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
* "Don Wash" <do*@wash.com> scripsit:
I'm using VB.NET to create a TreeView application and unfortunately I
could
not find "Key" property in Node items of the TreeView.


There is no direct replacement for this property. You can set up a
'Hashtable' and store your (key, 'TreeNode') pairs for fast lookup by a
key there.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #5

P: n/a
anybody plz...

Don

"Don Wash" <do*@wash.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
Hi There!

I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView.

We used to have "Key" property in TreeView node object in VB6.

What is the equivalent of "Key" property of TreeView node in VB.NET? Has the property name "Key" has been changed to something else? Or VB.NET does not
support the "Key" property anymore? If so what are the alternatives?

What I need is I need to assign "Key" (which contains text and number) to
each node I add to the TreeView. So "Index" property won't help me. I need
something similar to "Key" property that is used to support in TreeView
Nodes of VB6.

Thanks all in advance!
Don

Nov 21 '05 #6

P: n/a
anybody plz...

Don

"Don Wash" <do*@wash.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
Hi There!

I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView.

We used to have "Key" property in TreeView node object in VB6.

What is the equivalent of "Key" property of TreeView node in VB.NET? Has the property name "Key" has been changed to something else? Or VB.NET does not
support the "Key" property anymore? If so what are the alternatives?

What I need is I need to assign "Key" (which contains text and number) to
each node I add to the TreeView. So "Index" property won't help me. I need
something similar to "Key" property that is used to support in TreeView
Nodes of VB6.

Thanks all in advance!
Don

Nov 21 '05 #7

P: n/a
Don,
Look carefully at how the TreeView Nodes are owned.

The TreeView itself only owns the root nodes, with indexes from 0 to however
many root nodes.

Each root node will own their children, their children will have indexes
from 0 to however many children each respective root has.

The grand children (of root) will have indexes from 0 to however many
children each parent (child of root) has respectively.

And so on.

In other words all the nodes in the following will have an index of 0,
except Grand Child 2 & Root 2 which will have indexes of 1.

Root 1 (index = 0)
Child 1 (index = 0)
Grand Child 1 (index = 0)
Great Grand Child 1 (index = 0)
Grand Child 2 (index = 1)
Great Grand Child 2 (index = 0)
Child 2 (index = 0)
Grand Child 3 (index = 0)
Great Grand Child 3 (index = 0)
Root 2 (index = 1)
Child 3 (index = 0)
Grand Child 4 (index = 0)
Great Grand Child 4 (index = 0)

If you need to index the nodes by both Key & Index, where Index is across
all nodes in the tree) I would recommend a
System.Collections.Specialized.NameValueCollection instead of a HashTable.
As the NameValueCollection supports indexing by both Key & Index.

Hope this helps
Jay

"Don Wash" <do*@wash.com> wrote in message
news:On*************@TK2MSFTNGP11.phx.gbl...
Thanks, I've tried HashTable method but it doesn't seems to work.

Here's the code...

With objNewNode
htMain.Add(strNodeKey, .Index)
htMain_IndexToKey.Add(.Index, strNodeKey)

.Text = "Node Item " & i
.ImageIndex = 1
End With

.Nodes.Add(objNewNode)

htMain and htMain_IndexToKey are HashTable objects. What happens is that
Index of objNewNode is always '0' (Zero).

So I though objNewNode is an independent TreeView Node which hasn't been
associated with the real TreeView control and I tried this code instead...

Dim intNodeIndex as Integer = .Nodes.Add(objNewNode)

htMain.Add(strNodeKey, intNodeIndex )
htMain_IndexToKey.Add(intNodeIndex , strNodeKey)

and still intNodeIndex equal '0' every time. How can I get the actual Node's index currently being added to the TreeView Nodes collection?

Thanks again!

Don

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
* "Don Wash" <do*@wash.com> scripsit:
I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView.


There is no direct replacement for this property. You can set up a
'Hashtable' and store your (key, 'TreeNode') pairs for fast lookup by a
key there.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #8

P: n/a

' set the key:
aTreeNode.Tag = aKey

' get the key:
aKey = CStr(aTreeNode.Tag)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.