|
| 1 | +Attribute VB_Name = "modListview" |
| 2 | +Option Explicit |
| 3 | + |
| 4 | +Private Const LVM_FIRST = &H1000 |
| 5 | +Private Const LVM_GETNEXTITEM = (LVM_FIRST + 12) |
| 6 | +Private Const LVNI_SELECTED = &H2 |
| 7 | +Private Const LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50) |
| 8 | +Private Const LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54 |
| 9 | +Private Const LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55 |
| 10 | +Private Const LVS_EX_FULLROWSELECT = &H20 |
| 11 | +Private Const LVIF_TEXT = &H1 |
| 12 | +Private Const LVM_SETITEMSTATE As Long = (LVM_FIRST + 43) |
| 13 | +Private Const LVM_GETITEMSTATE As Long = (LVM_FIRST + 44) |
| 14 | +Private Const LVM_GETITEMTEXT As Long = (LVM_FIRST + 45) |
| 15 | + |
| 16 | +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 |
| 17 | + |
| 18 | + |
| 19 | +Public Function GetSelectedItemsFromListview(oListview As ListView) As Collection |
| 20 | +Dim lCurSelectedItemIndex As Long |
| 21 | +Dim myCol As Collection |
| 22 | +Dim myListItem As ListItem |
| 23 | +Dim i |
| 24 | + |
| 25 | + 'begin/start position in the listview |
| 26 | + lCurSelectedItemIndex = -1 |
| 27 | + 'create collection to hold selected items |
| 28 | + Set myCol = New Collection |
| 29 | + |
| 30 | + For i = 1 To CountSelectedItemsInListview(oListview) |
| 31 | + 'get the itemx index from the selected (current)item |
| 32 | + lCurSelectedItemIndex = SendMessage(oListview.hwnd, LVM_GETNEXTITEM, lCurSelectedItemIndex, ByVal LVNI_SELECTED) |
| 33 | + 'add the listitem to the collection |
| 34 | + myCol.Add oListview.ListItems.Item(lCurSelectedItemIndex + 1) |
| 35 | + Next i |
| 36 | + |
| 37 | + 'return the collection |
| 38 | + Set GetSelectedItemsFromListview = myCol |
| 39 | + |
| 40 | +End Function |
| 41 | +Public Function CountSelectedItemsInListview(oListview As ListView) As Long |
| 42 | + |
| 43 | + 'count the selected items |
| 44 | + CountSelectedItemsInListview = SendMessage(oListview.hwnd, LVM_GETSELECTEDCOUNT, 0, 0) |
| 45 | + |
| 46 | +End Function |
| 47 | + |
0 commit comments