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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Set ListView Item to Selected

Set ListView Item to Selected

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 1 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.
  • V Offline
    V Offline
    VFaul
    wrote on last edited by
    #1

    I have a ListView control in a form. I want to add a "Select All" button on the form that selects all items in the ListView control. I cannot find a way to do this. The "SelectedIndices" and "SelectedItems" are readonly properties. How do I programatically select an item in the ListView?

    V 1 Reply Last reply
    0
    • V VFaul

      I have a ListView control in a form. I want to add a "Select All" button on the form that selects all items in the ListView control. I cannot find a way to do this. The "SelectedIndices" and "SelectedItems" are readonly properties. How do I programatically select an item in the ListView?

      V Offline
      V Offline
      VFaul
      wrote on last edited by
      #2

      Here's how you do it: For Each item As ListViewItem In lv.Items item.Selected = True Next lv.Focus() Note that you need need to set the focus back to the ListView control, because the items won't be highlighted when the control does not have focus (by default, lv.HideSelection = true). Instead of giving focus back to the control, you could set the lv.HideSelection to false, but the highlight will be gray instead of blue (when the control does not have focus).

      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