Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom TreeView Control

Status
Not open for further replies.

KoRUPT

Programmer
Jul 25, 2002
25
CA
Hi. I do not have much experience making custom controls in C# (or C++ for that matter) and would like a basic rundown of how to do it. For example, if I wanted a TreeView that is identical to the original except that each node has 1 extra string property called "Tag2". How would I go about doing this?

Any help, big or small is appreciated. Thank you.
 
I do something similar, its a new kind of node you need to create, add a new class and it should look something like this... You would then just create a new one of your nodes

(myTreeNode aNode = new myTreeNode("SomeText", "Some other Text for Tag2") )

and add it to the treeview in question. Namespace etc will be whatever you need, this is just cut and pasted from one of my recent projects to give you an idea.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace ttControls
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class myTreeNode : TreeNode
{
private string Tag2;


public myTreeNode(string myText, int myTag)
{
//
// TODO: Add constructor logic here
//
this.Text=myText;
this.Tag2=myTag;

}

public string tag2
{
get {return Tag2;}
}

}
}
 
Thanks MrMcauber. I presume I just cast my derived node to the base class when I add/access it? I'll do some testing and let you know.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top