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. C#
  4. ListView getting the Selected Item

ListView getting the Selected Item

Scheduled Pinned Locked Moved C#
question
4 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.
  • A Offline
    A Offline
    albean
    wrote on last edited by
    #1

    For a ListView with MultiSelect = false how do I find the label of the selected Icon? I’m hooking the SelectedIndexChanged event. And then it looks like I’m forced to iterate the SelectedItems collection with a foreach loop. This seems stupid since only one item can be selected when MultiSelect = false. I would like to do something like:

    MyListView.Items(MyListView.SelectedIndex).Name

    But there is no SelectedIndex property and does not look like I can use MyListView.Items in that way. Do I have to iterate the SelectedItems collection for the single selected Item? How do you guys do this?

    D 1 Reply Last reply
    0
    • A albean

      For a ListView with MultiSelect = false how do I find the label of the selected Icon? I’m hooking the SelectedIndexChanged event. And then it looks like I’m forced to iterate the SelectedItems collection with a foreach loop. This seems stupid since only one item can be selected when MultiSelect = false. I would like to do something like:

      MyListView.Items(MyListView.SelectedIndex).Name

      But there is no SelectedIndex property and does not look like I can use MyListView.Items in that way. Do I have to iterate the SelectedItems collection for the single selected Item? How do you guys do this?

      D Offline
      D Offline
      draco_iii
      wrote on last edited by
      #2

      This gives access to the "Selected Index". listView1.FocusedItem.SubItems[0]

      A 1 Reply Last reply
      0
      • D draco_iii

        This gives access to the "Selected Index". listView1.FocusedItem.SubItems[0]

        A Offline
        A Offline
        albean
        wrote on last edited by
        #3

        Thanks Draco, Not sure how I missed that one. I added this to the click event:

        listView1.FocusedItem.Text

        D 1 Reply Last reply
        0
        • A albean

          Thanks Draco, Not sure how I missed that one. I added this to the click event:

          listView1.FocusedItem.Text

          D Offline
          D Offline
          David Stone
          wrote on last edited by
          #4

          albean wrote: Not sure how I missed that one. Because it's not really a standard thing in the framework. Usually it's SelectedIndex or SelectedItem. You could also use the SelectedIndices property...and then the first selected index would be listView1.SelectedIndices[0].


          Hawaian shirts and shorts work too in Summer. People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage... -Anna-Jayne Metcalfe on Paintballing

          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