Treeview deselecting nodes?
-
Hello, I'm using a treeview and I have selected several nodes. Now I'd like to clear those node selections so that there are no nodes selected in the treeview. The only way I've found to do this is to reload the treeview with the object, which sets it back to original state. But there's got to be a better way. Anyone have any ideas? Thanks in advance, --PhB PhrankBooth
-
Hello, I'm using a treeview and I have selected several nodes. Now I'd like to clear those node selections so that there are no nodes selected in the treeview. The only way I've found to do this is to reload the treeview with the object, which sets it back to original state. But there's got to be a better way. Anyone have any ideas? Thanks in advance, --PhB PhrankBooth
As far as I know, a treeview can only have one selected node, which you can retrieve with the SelectedNode property. Therefore, I'm not sure what are you refering to when you say that you have selected *several* nodes - maybe checked, like if the treeview is set to diplay checkboxes, and you refer to the checked nodes? Anyways, if you want to "deselect" the one and only node that could be selected in a treeview, try setting the SelectedNode property to null. Otherwise, if you want to "uncheck" any checked node, you must navigate the nodes, say recursively, and set the Checked property of each node to false. Assuming you have a treeview named treeView in your form, create a method called setCheck and call it from wherever you want to perform the clearing of checked nodes (or checking them for that matter):
private void setCheck(TreeNode node, bool isChecked) { if(node != null) { node.Checked = isChecked; foreach(TreeNode child in node.Nodes) { setCheck(child, isChecked); } } }
Call this method like this://********************************* bool isChecked = false; //it will clear the check, true will set the check foreach(TreeNode node in treeView.Nodes) { setCheck(node, false); } //**********************************
Hope it helps. -
Hello, I'm using a treeview and I have selected several nodes. Now I'd like to clear those node selections so that there are no nodes selected in the treeview. The only way I've found to do this is to reload the treeview with the object, which sets it back to original state. But there's got to be a better way. Anyone have any ideas? Thanks in advance, --PhB PhrankBooth
treeView1.HideSelection=true
:) Sreejith Nair [ My Articles ]