为了自由,幸福而不断奋斗,前行!!!

一笑看风云过....

博客园 首页 新随笔 联系 订阅 管理

一、目的:自定义TreeNode属性,让控件可以存储更多属性。有利于开发
二、方法:

public class GroupTreeNode : TreeNode
    {
        private IPAddress ip;
        private HostStatus status;
        public HostStatus Status
        {
            set { status = value; }
            get { return status; }
        }
        public IPAddress IP
        {
            set { ip = value; }
            get { return ip; }
        }

        public GroupTreeNode()
            : base()
        {

        }
        public GroupTreeNode(string text, int imageIndex, int selectedImageIndex, IPAddress address)
            : base(text, imageIndex, selectedImageIndex)
        {
            this.ip = address;
        }
    }

三、应用

Code

四、其他
循环访问 TreeView 控件的所有节点

private void PrintRecursive(TreeNode treeNode)
{
// Print the node.
System.Diagnostics.Debug.WriteLine(treeNode.Text);
MessageBox.Show(treeNode.Text);
// Print each node recursively.
foreach (TreeNode tn in treeNode.Nodes)
{
PrintRecursive(tn);
}
}
// Call the procedure using the TreeView.
private void CallRecursive(TreeView treeView)
{
// Print each node recursively.
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
PrintRecursive(n);
}
}
posted on 2008-09-18 15:22  YAO'STAR  阅读(1875)  评论(0编辑  收藏  举报