1
我一直在玩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;
}
我敢肯定,必須有一些簡單的方法來從單個節點刪除複選框,而不是所有的人一下子,我只是不能似乎到處都找不到....
是否有可能灰化節點或只是複選框,使它變得不可選? – Axxelsian
不是我所知道的。圖形選項是一個很好的方法。它給你完全的控制。 – RedEyedMonster