Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add more values to a TreeNode class in C#

Tags:

c#

treeview

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

like image 833
Caslav Avatar asked Mar 22 '10 09:03

Caslav


1 Answers

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;
like image 149
Rhapsody Avatar answered Sep 17 '22 21:09

Rhapsody