using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
                treeView1.Nodes.Add(textBox1.Text);
            else
                MessageBox.Show("Enter a node name first");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;
            if (node == null)
                MessageBox.Show("Select a node ");
            else if (textBox1.Text == "")
                MessageBox.Show("Enter a node name ");
            else
                node.Nodes.Add(textBox1.Text);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;
            if (node == null)
                MessageBox.Show("Select a node ");
            else
                node.Remove();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;
            if (node == null)
                MessageBox.Show("Select a node ");
            else
                node.Nodes.Clear();
        }
    }
}
