删除特定节点的复选框

时间:2012-05-17 17:42:17

标签: c# treeview nodes

我最近一直在使用treenodes,我希望能够在创建后从特定节点中删除一个复选框,具体取决于我的控件是1还是0.我拥有大部分代码完成后,这部分我不太清楚如何实施。

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; 
    } 

我确信必须有一些简单的方法可以从单个节点中删除一个复选框,而不是一次性删除所有这些复选框,我似乎无法在任何地方找到它....

1 个答案:

答案 0 :(得分:1)

暂时没有这样做,但从来没有可能删除单个复选框。解决方法是关闭复选框并使用图形而不是使用click事件在checked&amp;之间切换。选中。甚至可以扩展到更复杂的状态。