Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Treeview deselecting nodes?

Treeview deselecting nodes?

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PhrankBooth
    wrote on last edited by
    #1

    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

    P S 2 Replies Last reply
    0
    • P 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

      P Offline
      P Offline
      Paul Voicu
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • P 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

        S Offline
        S Offline
        sreejith ss nair
        wrote on last edited by
        #3

        treeView1.HideSelection=true :) Sreejith Nair [ My Articles ]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups