Link to home
Start Free TrialLog in
Avatar of weirddemon
weirddemon

asked on

Get ListViewItem Checked state by Index in VB .NET

I've been trying to commit an action based on the Checked Index of that item. I've tried a bunch of different ways and I've come up with nothing so far.

Couple of things first:

I cannot use the ListViews events. I must be able to determine the Checked state from a button's event.

Again, I need to check a specific index (0-4) and then commit an action based on that. The following is an example that I've tried. More importantly, it will give you a better idea of what I need:

If ListView1.CheckedIndices(0) = True Then
     'Checked
Else
      'Not checked
End If
Avatar of Hawkvalley1
Hawkvalley1
Flag of United States of America image

Select Case listview1.SelectedIndex
  Case 0
     'something
  Case 1
    'something
  Case 2
     'something
  Case 3
      'something
  Case 4
     'something
End Select
Avatar of weirddemon
weirddemon

ASKER

Hawkvalley,

How does that apply at all?
Avatar of Wayne Taylor (webtubbs)
For a start, if no items are checked, ListView1.CheckedIndices will return an empty collection, so you can first check that there are indeed some items checked in the listview....

    If ListView1.CheckedIndices.Count > 0 Then
        'there is at least 1 item checked
    Else
        'there are no items checked
    End If

Wayne
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Webtubbs.

I thought I had tried something like before and it gave me an error, but it appears to be working now.

Thanks