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.
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.