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