• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

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
0
weirddemon
Asked:
weirddemon
  • 2
  • 2
1 Solution
 
Hawkvalley1Commented:
Select Case listview1.SelectedIndex
  Case 0
     'something
  Case 1
    'something
  Case 2
     'something
  Case 3
      'something
  Case 4
     'something
End Select
0
 
weirddemonAuthor Commented:
Hawkvalley,

How does that apply at all?
0
 
Wayne Taylor (webtubbs)Commented:
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
0
 
Wayne Taylor (webtubbs)Commented:
Once you've done that, you can then determine if your specific items as checked....

    If ListView1.CheckedIndices.Count > 0 Then
        If ListView1.Items(0).Checked Then
            'your code
        End If
    Else
        'there are no items checked
    End If

Wayne
0
 
weirddemonAuthor Commented:
Thanks Webtubbs.

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

Thanks
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now