. Assign ID value to the node of the TreeView control in net

Source: Internet
Author: User

1, first of all, the TreeView control is a control that belongs to the WinForm.

2, with accustomed WebForm friend certainly knew, WebForm under the TreeView control has the Selectednode.text and the Selectednode.value these two attributes. However, the TreeView control under WinForm does not selectednode.value this property, so many friends have encountered a problem, how to assign a value such as ID to the TreeView?

3, most WinForm controls have the tag attribute. Yes, we're just going to use tag to assign the ID value to the node. The code is as follows:

TreeNoderoot=newTreeNode();//创建一个根节点
root.Text="根节点";
treeView1.Nodes.Add(root);
TreeNodetn1=newTreeNode();
tn1.Tag=1;//可以对Tag属性赋值,即节点1的id为1
tn1.Text="节点1";
root.Nodes.Add(tn1);
treeView1.ExpandAll();
treeView1.ShowLines=true;

4,int Tnid=convert.toint32 (TN1. TAG); The variable tnid is defined as the ID of Node 1, so that the ID value is taken.

5, it's actually a very simple little example, but when I do WinForm program because this problem delayed some time, there is no solution on the Internet, I asked in csdn when many friends give me advice and solutions, once again to these friends to thank, but also hope that in the future encounter this "episode" Friends of the problem to see my post can not delay the time to solve such problems, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.