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. WPF
  4. How to get TreeView SelectedItem/Value?

How to get TreeView SelectedItem/Value?

Scheduled Pinned Locked Moved WPF
tutorialdata-structuresquestion
6 Posts 4 Posters 6 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.
  • B Offline
    B Offline
    BeeDev
    wrote on last edited by
    #1

    I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel

    S M U 3 Replies Last reply
    0
    • B BeeDev

      I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel

      S Offline
      S Offline
      SledgeHammer01
      wrote on last edited by
      #2

      Are you only going one way? UI -> VM? If so, there is a SelectedItem bindable property on the TreeView that you can use. If you want two-way binding (set the selection from the VM), that is a lot more work.

      B 1 Reply Last reply
      0
      • B BeeDev

        I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        This guy [^]has some excellent treeview article which may help you.

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • S SledgeHammer01

          Are you only going one way? UI -> VM? If so, there is a SelectedItem bindable property on the TreeView that you can use. If you want two-way binding (set the selection from the VM), that is a lot more work.

          B Offline
          B Offline
          BeeDev
          wrote on last edited by
          #4

          It is binding from UI to VM. I just need to get the value of the selecteditem, and the SelectedItem of the TreeView is Read Only. So how do I get the Value of the Selected Item? Thanks in advance.

          S 1 Reply Last reply
          0
          • B BeeDev

            It is binding from UI to VM. I just need to get the value of the selecteditem, and the SelectedItem of the TreeView is Read Only. So how do I get the Value of the Selected Item? Thanks in advance.

            S Offline
            S Offline
            SledgeHammer01
            wrote on last edited by
            #5

            So what is the issue? SelectedItem contains your selected item. It is only read only to you. The TreeView control sets internally. You do need to use one way binding though.

            1 Reply Last reply
            0
            • B BeeDev

              I have Multiple Lists that are bound to multiple TreeViewItems within the Tree as in the code below. This is working perfectly to display the bound items; however, I couldn't figure out how to get the selected item value. For example, if the user clicks the color Blue, I would like to be able to get that value, in this case "Blue," in order to be able to bind to a property in the ViewModel

              U Offline
              U Offline
              USAFHokie80
              wrote on last edited by
              #6

              Why can't you just bind SelectedItem from the TreeView to your VM ?

              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