Listview vb 2008

kimt
05-04-2011, 02:29 PM
Have a populated listview with check boxes. If the item is checked I want to send it to report for printing. This code is bypassed:

Private Sub GetSelectedItems()
If Not Me.ListView1.SelectedItems.Count = 0 Then
For i = 1 To ListView1.SelectedItems.Count
MsgBox(Me.ListView1.SelectedItems.ToString)
Next
End If
End Sub

Count is always = 0. This seems to work only if the item is double clicked. And then only one item is returned in the msgbox. MSDN says "The SelectedItems property will not contain any items if the property is accessed before the ListView handle is created, which typically occurs when ListView is initially loaded for display in the form. You can check to see if the handle is created with the IsHandleCreated property."

When I tried to check for the handle, an error said something about overloading. So I added this:
Public Overloads ReadOnly Property GetSelectdItems()
Get
If Not Me.ListView1.SelectedItems.Count = 0 Then
For i = 1 To ListView1.SelectedItems.Count
MsgBox(Me.ListView1.SelectedItems.ToString)
Next
End If
MsgBox(Me.ListView1.SelectedItems.ToString)
Return True
End Get
End Property
Which does not help. How to find the items checked/create the needed handle?

Thank you.

MattC455
05-19-2011, 04:12 AM
SelectedItems is used to detect if the actual item itself is selected (row is highlighted for instance).

Try this instead:


For i As Integer = 0 To ListView1.Items.Count
If ListView1.Items(i).Checked Then
'// Do Something
End If
Next

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum