I have a treeview with root root originally as Root. If I right-click on the Root node, I will have a context menu with some options like New and other, if I select New, I will add a node child to the Root node. If I right-click again on the Root node, and if Root has child nodes, I would like to clear all the child nodes and add a new node child, how can I do this
After all the final answer
if (tvwACH.HitTest(location).Node.Nodes.Count > 0 && tvwACH.SelectedNode.Parent == null ) { foreach (TreeNode node in tvwACH.Nodes) { node.Nodes.Clear(); } }
TreeNode.Nodes node, .
Clear , .
'right click', , Mouse Click, args TreeNodeMouseClickEventArgs node...
'right click'
void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == MouseButtons.Right) { TreeNode selectedNode = e.Node; } }
TreeNode.Nodes. count , , <
foreach (TreeNode node in treeview.Nodes) { if (node.ChildNodes.Count != 0) { //Node exists } else { //Node doesn't exists } }
Source: https://habr.com/ru/post/1766201/More articles:How to connect to a webpage inside a WPF menu item? - c #Why does the F # s Collections.Seq module basically override all Enumerable extension methods? - language-designQuery string Asp.Net - stringJavascript function argument handling - javascriptPHP - compress static css file using gzip - htmlChanging the value of a tree node - c #Permutation using two variables is not three? - programming-languages โโ| fooobar.comValidating a Django form, including using session data - pythonPHP How to delete lines less than 6 characters long - phpHow to make a PHP session expire when you close your browser OR some lengthy time - phpAll Articles