1
在我的应用程序中,我使用了树视图。当用户单击[+]展开节点时,该节点将变为选定节点。我怎样才能阻止呢?在扩展中选择C#treeview停止节点
private void tvFileStructure_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
if (e.Node.Text != "Network")
{
int unauthorisedAccessExceptions = 0;
try
{
TreeNode newSelected = e.Node;
DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
TreeNode child = newSelected.FirstNode;
if (child.Level < 3)
{
while (child != null)
{
// Only try to populate if there aren't any children
if (child.FirstNode == null)
{
DirectoryInfo[] subDirs = ((DirectoryInfo)child.Tag).GetDirectories();
if (subDirs.Length != 0)
{
getDirectories(subDirs, child);
}
}
child = child.NextNode;
}
}
}
catch (UnauthorizedAccessException)
{
unauthorisedAccessExceptions++;
}
if (unauthorisedAccessExceptions > 0)
{
MessageBox.Show("There were " + unauthorisedAccessExceptions.ToString() + " folder(s) that you do not have access to.", "Warning...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
WPF或WinForms的? – thumbmunkeys
应用程序在winforms中 – bobble14988
Winform的TreeView控件默认不会这样做。邮政编码,实际上再现了问题。 –