Axxelsian
Axxelsian

Reputation: 807

Remove a specific node's Checkbox

I've been playing with treenodes as of late, and i want to be able to remove a checkbox from a specific node once it has been created depending on if my control is 1 or 0. I have the majority of the code completed, just this part I'm not quite sure how to implement.

private void ListDirectory(TreeView treeView, string path) 
        {     
            treeView.Nodes.Clear();   
            var rootDirectoryInfo = new DirectoryInfo(path);    
            treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo)); 
        }     
    private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo) 
    {



        var directoryNode = new TreeNode(directoryInfo.Name);

        foreach (var directory in directoryInfo.GetDirectories())
            directoryNode.Nodes.Add(CreateDirectoryNode(directory));

        foreach (var file in directoryInfo.GetFiles())
        {
            int check =0;                  
            try
            {
                string s = "";
                s = directoryInfo.FullName + "\\" + file.Name;
                List<string> row, row2 = new List<string>();

                using (StreamReader readFile = new StreamReader(s))
                {
                    row = (readFile.ReadLine().Split(',').ToList());
                    try 
                    {
                        row2 = (readFile.ReadLine().Split(',').ToList());
                        check = 1;
                    }
                    catch { }
                }

                TreeNode[] headerNodes = new TreeNode[row.Count];

                for (int i = 0; i < row.Count; i++)
                {
                    if (check == 0)
                    {
                        //IN HERE SOMEWHERE//
                        headerNodes[i].BackColor = Color.Red;
                        headerNodes[i].ForeColor = Color.White;
                    }
                    headerNodes[i] = new TreeNode(row[i]);

                }
                directoryNode.Nodes.Add(new TreeNode(file.Name, headerNodes));
            }
            catch 
            {
                directoryNode.Nodes.Add(new TreeNode(file.Name));
            }
        }         
        return directoryNode; 
    } 

I'm sure there must be some simple way to remove a checkbox from a single node, rather than all of them at once, i just cant seem to find it anywhere....

Upvotes: 1

Views: 266

Answers (1)

Nigel B
Nigel B

Reputation: 3597

Haven't done this for a while but it never used to be possible to remove individual checkboxes. A workaround is to switch off checkboxes and use a graphic instead using the click event to toggle between checked & unchecked. Can even be extended for more complex states.

Upvotes: 1

Related Questions