TreeViewチェックボックス

■TreeViewのチェックボックス
 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        TreeNode tn = new TreeNode(@"ROOT");
        this.treeView1.PathSeparator = @"\";
        this.GetDirectorys(@"C:\Documents and Settings\xxxx\My Documents", tn);
        this.treeView1.Nodes.Add(tn);
        this.treeView1.ExpandAll();
    }

    private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
    {
        this.treeView1.BeginUpdate();
        this.SetChildNodeChecked(e.Node.FirstNode, e.Node.Checked);
        this.treeView1.EndUpdate();
    }

    private void GetDirectorys(string argDirctory,TreeNode argTreeNode)
    {
        TreeNode tn = new TreeNode(Path.GetFileName(argDirctory));
        argTreeNode.Nodes.Add(tn);
        string[] dirArray = Directory.GetDirectories(argDirctory);

        foreach (string dir in dirArray)
        {
            this.GetDirectorys(dir, tn);
        }
    }

    private void SetChildNodeChecked(TreeNode argTreeNode,bool argCheckedFlag)
    {
        for (TreeNode tn = argTreeNode; null != tn; tn = tn.NextNode)
        {
            tn.Checked = argCheckedFlag;
            if (null != tn.FirstNode)
            {
                this.SetChildNodeChecked(tn.FirstNode, argCheckedFlag);
            }
        }
    }
}