[C#] แสดงผลแบบ TreeView

หน้าจอ


โค้ด

namespace treeviewDisplay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            TreeNode anyNode;
            anyNode = treeView1.Nodes.Add("Alphabet");
            anyNode.Nodes.Add("A");
            anyNode.Nodes.Add("B");
            anyNode = treeView1.Nodes.Add("Number");
            anyNode.Nodes.Add("1");
            anyNode.Nodes.Add("2");
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if(e.Action == TreeViewAction.ByMouse)
            {
                label1.Text = e.Node.FullPath;
            }
        }
    }
}
Previous
Next Post »