본문 바로가기

스터디/C#.NET:자료

TreeView 이용하기

전체 소스
      WATTreeView.zip

 

특별히 설명은 필요 없을거 같습니다.




using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

 

namespace WATTreeView

{

    public partial class Form1 : Form

    {

        Random m_random = new Random(); // 랜덤인스턴스생성

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            treeView1.Nodes.Clear();

        }

 

        // 선택된노드에노드추가하기

        private void button1_Click(object sender, EventArgs e)

        {

            TreeNode node = treeView1.SelectedNode;

            if (null == node)

                treeView1.Nodes.Add(m_random.Next(0, 100).ToString());

            else

            {

                node.Nodes.Add(m_random.Next(0, 100).ToString());

                node.Expand();

            }

        }

 

        // 선택노드삭제

        private void button2_Click(object sender, EventArgs e)

        {

            TreeNode node = treeView1.SelectedNode;

            if (null != node)

            {

                node.Remove();

            }

        }

 

        // 체크된노드삭제

        private void btnDelCheck_Click(object sender, EventArgs e)

        {

            foreach (TreeNode n in treeView1.Nodes)

            {

                if (n.Checked) n.Remove();

            }

        }

    }

}


출처: http://whiteat.com/38407