本文介绍了Treeview.nodes.clear引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试清除树视图,但是当我检查Treeview.node.count为1
时,它抛出异常"ObjectReference not set"
所以我想着怎么会发生此错误.
Hi,
I am trying to clear the treeview but it is throwing an exception "ObjectReference not set" when i checked the Treeview.node.count it is 1
so iam thinking how come this error occur.
private void LoadLayout(Layout result) {
TreeView view = dtLayout;
view.SuspendLayout();
view.Nodes.Clear();---------------------------->here the exception occur
TreeNode root = new TreeNode("root",result.Label,result.ImageKey) { Tag = result };
view.Nodes.Add(root);
AddTreeNodes(result.Children,root);
root.Expand();
view.SelectedNode = SelectNode(view.Nodes[0]);
view.ResumeLayout();
}
推荐答案
这篇关于Treeview.nodes.clear引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!