treenode

How to deep copy a Binary Tree?

不羁岁月 提交于 2019-11-27 01:58:44
问题 I would like using my own Node class to implement tree structure in Java. But I'm confused how to do a deep copy to copy a tree. My Node class would be like this: public class Node{ private String value; private Node leftChild; private Node rightChild; .... I'm new to recursion, so is there any code I can study? Thank you! 回答1: try class Node { private String value; private Node left; private Node right; public Node(String value, Node left, Node right) { this.value = value; ... } Node copy()

How to disable a WinForms TreeView node checkbox?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 01:58:12
I need to be able to disable some of the checkboxes in a TreeView control of a WinForms application, but there's no such functionality built-in to the standard TreeView control. I am already using the TreeView.BeforeCheck event and cancel it if the node is disabled and that works perfectly fine. I also change the ForeColor of the disabled nodes to GrayText. Does anyone have a simple and robust solution? Since there's support in C++ we can resolve it using p/invoke. Here's the setup for the p/invoke part, just make it available to the calling class. // constants used to hide a checkbox public

Is there a method for searching for TreeNode.Text field in TreeView.Nodes collection?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 22:53:20
问题 Like this: TreeNode[] treeNodes = treeView.Nodes.Find(searchString, true); but I want it to search in the text field instead of the name field. 回答1: I am not aware of any inbuilt method but you may use LINQ TreeNode[] treeNodes = treeView.Nodes .Cast<TreeNode>() .Where(r => r.Text == "yourText") .ToArray(); 回答2: To search all tree nodes (not only the direct child nodes) you can use the extension method below var nodes = treeView1.FlattenTree() .Where(n => n.Text == "sometext") .ToList(); --

How to disable a WinForms TreeView node checkbox?

 ̄綄美尐妖づ 提交于 2019-11-26 12:29:32
问题 I need to be able to disable some of the checkboxes in a TreeView control of a WinForms application, but there\'s no such functionality built-in to the standard TreeView control. I am already using the TreeView.BeforeCheck event and cancel it if the node is disabled and that works perfectly fine. I also change the ForeColor of the disabled nodes to GrayText. Does anyone have a simple and robust solution? 回答1: Since there's support in C++ we can resolve it using p/invoke. Here's the setup for

Get Edited TreeNode from a CellEditorListener

眉间皱痕 提交于 2019-11-26 03:27:05
问题 Earlier I asked how to fire an event when a TreeNode was renamed (here). My question was answered, but I ran into another problem. I need to access the TreeNode that is being edited in the CellEditorListener\'s editingStopped event. This is the code I have to do so: package com.gamecreator; import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.tree.DefaultTreeCellEditor; public class CustomCellEditorListener implements CellEditorListener {