tags:

views:

232

answers:

2

A TreeNode class has

Text Name Tag

I need to assign more values to a TreeNode class like float1, float2, ... float6.

How can I do this??? pls help.

Thx, Caslav

+2  A: 

You can create a new class which inherits the TreeNode. For each value you want to store in the treenode, create a property for that value. When working with the Treeview, simply cast the TreeNode to your custom TreeNode class.

Example:

public class JobTreeNode : TreeNode {

    private int intField1;

    public int Field1 {
        get {
            return intField1;
        }
        set {
            intField1 = value;
        }
    }
}

Usage (added after comments)

// Add the node
JobTreeNode CustomNode = new JobTreeNode();
CustomNode.Text = "Test";
CustomNode.Field1 = 10
treeView1.Nodes.add(CustomNode);


// SelectedNode 
((CustomNode)(treeView1.SelectedNode)).Field1;
Rhapsody
I tried that but I cannot display values in textbox when I select node.Example:textbox1.Text = treeView1.SelectedNode.Name.ToString(); <-- workstextbox2.Text = treeView1.SelectedNode.IntField or IntField1.ToString(); <-- doesn`t work
Caslav
You have to cast the SelectedNode.Something like this: ((CustomNode)(treeView1.SelectedNode)).Field1;
Rhapsody
You also have to make sure you _Add_ JobTreeNode elements.
Henk Holterman
Thank you very VERY much... The casting was the problem.Now it works like a charm!!Cheers
Caslav
A: 

The Tag property of TreeNode is "object". Can't you just store your data in there using a dataclass of some kind?

Christian W