LunchMarble
LunchMarble

Reputation: 5141

How do I use TreeView with my Tree Datastructure? C# .NET

I have a Tree and load it recursively into my TreeView on my form. The problem is, I do not know how to find out which object in my Tree that I am selected on when I select a node in my TreeView. Any ideas?

Upvotes: 0

Views: 551

Answers (3)

CharithJ
CharithJ

Reputation: 47500

If you have a unique id for each record you can assign that id as the TreeNode.Name. TreeNode.Tag is another option.

Upvotes: 0

Dulini Atapattu
Dulini Atapattu

Reputation: 2735

The TreeView nodes (TreeNodes) have properties like Level, Tag, Text etc. The Level property lets you identify in which level is your TreeNode in the TreeView and the Tag and Text properties may let you identify your node uniquely. You may also add same kind of properties to your Tree too and thus you may compare them relevantly and do the conversion you require...

Hope this helps...

Upvotes: 0

SLaks
SLaks

Reputation: 887275

You can set the TreeNode's Tag property to the corresponding instance from your object model.

Upvotes: 3

Related Questions