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. Selecting an item in a listview

Selecting an item in a listview

Scheduled Pinned Locked Moved Visual Basic
helpquestion
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.
  • H Offline
    H Offline
    Haim Yulzari
    wrote on last edited by
    #1

    In a small application I write I use a listview in Details view with check boxes. The listview has 3 rows and 2 columns. The second column of each row is initially empty. When I click a check box to check it, I perform some computation and insert the result into the second column. When I uncheck the box, the column is cleared. My problem: I couldn't find a simple way to determine in which row the check box I clicked is located. I've finally done the following: in the ItemCheck event of the listview I prepare a list of the currently checked rows. Then I start a timer with an interval of 250 ms that runs only once (AutoReset = False). In the Elapsed event of the timer I prepare another list of checked rows. This list contains the updated state of the box I clicked. I can find the row of the box I clicked by comparing the 2 lists. This method works but I feel it's a little cumbersome. Is there a better way? Thanks!

    S 1 Reply Last reply
    0
    • H Haim Yulzari

      In a small application I write I use a listview in Details view with check boxes. The listview has 3 rows and 2 columns. The second column of each row is initially empty. When I click a check box to check it, I perform some computation and insert the result into the second column. When I uncheck the box, the column is cleared. My problem: I couldn't find a simple way to determine in which row the check box I clicked is located. I've finally done the following: in the ItemCheck event of the listview I prepare a list of the currently checked rows. Then I start a timer with an interval of 250 ms that runs only once (AutoReset = False). In the Elapsed event of the timer I prepare another list of checked rows. This list contains the updated state of the box I clicked. I can find the row of the box I clicked by comparing the 2 lists. This method works but I feel it's a little cumbersome. Is there a better way? Thanks!

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      Isn't the list item you checked the selected item? If so, you can use listView.SelectedItems(0) will get you the selected item. Even otherwise, you can loop through the list of items and find out which one was checked, instead of doing it the way you are doing now. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      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