VB and VBA Users Source Code: Remove the selected items from a ListView
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Remove the selected items from a ListView
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, January 09, 2001
Hits:
916
Category:
Windows API
Article:
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. 'Author : Andrew Baker 'Date : 23/07/2000 18:52 'Notes : Requires a reference to MSCOMCTL.OCX or COMCTL.OCX 'Revisions : 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
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder