Visual Basic > Forms
Remove the selected items from a ListView
Remove the selected items from a ListView To remove the selected items from a listview, use the following routine. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long 'Purpose : Removes all the Selected Items from a ListView 'Inputs : lvRemoveSelected The Listview to remove the selected items from 'Outputs : Returns an error number if an error occurred, else returns 0. 'Notes : Requires a reference to MSCOMCTL.OCX or COMCTL.OCX Function LVRemoveSelectedItems(lvRemoveSelected As ListView) As Long Const LVM_FIRST = &H1000, LVM_GETNEXTITEM = (LVM_FIRST + 12), LVNI_SELECTED = &H2, LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50) Dim sThisItem As Long, lLvHwnd As Long, lSelectedItem As Long, lItemsSelected As Long On Error GoTo ErrFailed With lvRemoveSelected lLvHwnd = .hwnd 'Get Listview handle .Visible = False 'For speed. Need to remove the line in VBA lItemsSelected = SendMessage(lLvHwnd, LVM_GETSELECTEDCOUNT, 0, ByVal 0&) For sThisItem = 1 To lItemsSelected lSelectedItem = SendMessage(lLvHwnd, LVM_GETNEXTITEM, -1, ByVal LVNI_SELECTED) + 1 .ListItems.Remove lSelectedItem 'Remove selected item Next .Visible = True 'For speed. Need to remove the line in VBA End With Exit Function ErrFailed: LVRemoveSelectedItems = Err.Number On Error Resume Next End Function
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows