Results 1 to 2 of 2

Thread: How can I remove item(s) from ListView1?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Location
    China
    Posts
    25

    Exclamation

    I wanna remove the selected item(s) from ListView1,but VB says "error" when useing the following codes:
    -------------------------------------------------------------------------
    Private Sub RemoveItems()
    If ListView1.SelectedItem Is Nothing Then
    Exit Sub
    Else
    Dim Counter As Long, lvwCount As Long
    lvwCount = ListView1.ListItems.Count
    For Counter = 1 To lvwCount
    If ListView1.ListItems(Counter).Selected Then Exit For
    Next Counter
    ListView1.ListItems.Remove (Counter)
    Call RemoveItems
    End If
    End Sub
    ----------------------------------------------------------------------------
    When I all selected items moved from ListView1, I write the following code to debug:
    Debug.Print ListView1.SelectedItem Is Nothing
    And the output result IS NOT "True" ,It says "False".That is, the code " If ListView1.SelectedItem Is Nothing Then Exit Sub" is useless!
    Can everyone tell me hao can I remove the selected item(s) from ListView1?

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Code:
    Private Sub RemoveItems() 
        Dim Counter As Long, lvwCount As Long 
        lvwCount = ListView1.ListItems.Count 
        For Counter = lvwCount To 1 Step -1
            If ListView1.ListItems(Counter).Selected Then
                ListView1.ListItems.Remove (Counter)
            End If
        Next
    End Sub
    Good luck!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width