2个回答
展开全部
可以自己扩展属性来保存值。
using System;
using System.Windows.Forms;
namespace test1{
public partial class TreeviewEx : Form {
public TreeviewEx() {
InitializeComponent();
}
/// <summary>
/// 扩展TreeNode,增加需要的属性
/// </summary>
class MyTreeNode: TreeNode {
public string UserName { get; set; }
}
private void button1_Click(object sender, EventArgs e) {
for (int i = 0; i < 10; i++) {
MyTreeNode node = new MyTreeNode();
node.Text = string.Format("Node {0}", i);
node.UserName = string.Format("Name {0}", i + 100);
treeView1.Nodes.Add(node);
}
}
private void treeView1_DoubleClick(object sender, EventArgs e) {
if (treeView1.SelectedNode != null) {
MyTreeNode node = (MyTreeNode)treeView1.SelectedNode;
MessageBox.Show(node.UserName);
}
}
}
}
using System;
using System.Windows.Forms;
namespace test1{
public partial class TreeviewEx : Form {
public TreeviewEx() {
InitializeComponent();
}
/// <summary>
/// 扩展TreeNode,增加需要的属性
/// </summary>
class MyTreeNode: TreeNode {
public string UserName { get; set; }
}
private void button1_Click(object sender, EventArgs e) {
for (int i = 0; i < 10; i++) {
MyTreeNode node = new MyTreeNode();
node.Text = string.Format("Node {0}", i);
node.UserName = string.Format("Name {0}", i + 100);
treeView1.Nodes.Add(node);
}
}
private void treeView1_DoubleClick(object sender, EventArgs e) {
if (treeView1.SelectedNode != null) {
MyTreeNode node = (MyTreeNode)treeView1.SelectedNode;
MessageBox.Show(node.UserName);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询