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. Visual Basic
  4. How to get the selected index of a ListView item ?

How to get the selected index of a ListView item ?

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

    Hi, we use a ListView control in order to show thumbnails. After we add some thumbnails, we need to know which thumbnail(ListViewItem is selected or clicked/selected with the mouse) and for this we use ListView1_SelectedIndexChanged event. To know that, we want to know the slected index of the ListView so we use the .SelectedIndices(0) method, but it gets an exception error as shown below. Private Sub ListView1_SelectedIndexChanged(ByVal .....) Dim index as Integer index = ListView1.SelectedIndices(0) End Sub - ex {"InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index"} System.Exception Any idea how to retrieve the index of the selected ListViewItem?

    G 1 Reply Last reply
    0
    • N ninkk

      Hi, we use a ListView control in order to show thumbnails. After we add some thumbnails, we need to know which thumbnail(ListViewItem is selected or clicked/selected with the mouse) and for this we use ListView1_SelectedIndexChanged event. To know that, we want to know the slected index of the ListView so we use the .SelectedIndices(0) method, but it gets an exception error as shown below. Private Sub ListView1_SelectedIndexChanged(ByVal .....) Dim index as Integer index = ListView1.SelectedIndices(0) End Sub - ex {"InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index"} System.Exception Any idea how to retrieve the index of the selected ListViewItem?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You first have to check if SelectedIndices contains anything at all. The SelectedIndexChanged event is also triggered when the previously selected item is unselected, and then no item is selected and the collection is empty.

      --- single minded; short sighted; long gone;

      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