public void EditSelectedNode() { TreeNode node = tree.SelectedNode; while (!(node is ElementNode)) { if (node == null) { return; } node = node.Parent; } INode element = ((ElementNode)node).element; using (VBEditDialog dlg = new VBEditDialog(element)) { dlg.ShowDialog(); } ((ElementNode)node).Update(); }