Option Explicit
Private Type LVITEM Mask As Long Item As Long SubItem As Long State As Long StateMask As Long Text As String TextMax As Long Image As Long Param As Long Indent As Long End Type Private Const LVM_FIRST = &H1000& Private Const LVM_SETITEM = (LVM_FIRST + 6) Private Const LVM_SETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 54) Private Const LVM_GETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 55) Private Const LVS_EX_SUBITEMIMAGES = &H2& Private Const LVIF_IMAGE = &H2& 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 '_________________________________________________________ Private Sub Form_Load() Dim LV As LVITEM Dim lStyle As Long Dim li As ListItem ' Add a ListItem Set li = ListView1.ListItems.Add(, , "Item 1", , 1) li.SubItems(1) = "SubItem 1" ' Set the ListView style to show sub-item images lStyle = SendMessage(ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, _ ByVal 0&) lStyle = lStyle Or LVS_EX_SUBITEMIMAGES SendMessage ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, ByVal _ lStyle ' Change the ListItem's sub-item image With LV .Mask = LVIF_IMAGE .Item = li.Index - 1 .SubItem = 1 '1-based index of sub-item .Image = 1 '0-based index of list image End With SendMessage ListView1.hwnd, LVM_SETITEM, li.Index - 1, LV End Sub 'When run, this code will display a single ListItem with the first image as 'the Item 's icon and the second image as the sub-item's icon. ' From a newsgroup posting by Peter F. Dubuque 'To begin, drop a ListView control and an ImageList control onto a form. 'Add two 16x16 images to the ImageList. Set the ListView to display itself 'in report style, add two column headers, then bind the ImageList control 'to the ListView as the small icon image list. ' 'Now paste the following code into the form's code window: Option Explicit Private Type LVITEM Mask As Long Item As Long SubItem As Long State As Long StateMask As Long Text As String TextMax As Long Image As Long Param As Long Indent As Long End Type Private Const LVM_FIRST = &H1000& Private Const LVM_SETITEM = (LVM_FIRST + 6) Private Const LVM_SETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 54) Private Const LVM_GETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 55) Private Const LVS_EX_SUBITEMIMAGES = &H2& Private Const LVIF_IMAGE = &H2& 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 Private Sub Form_Load() Dim LV As LVITEM Dim lStyle As Long Dim li As ListItem ' Add a ListItem Set li = ListView1.ListItems.Add(, , "Item 1", , 1) li.SubItems(1) = "SubItem 1" ' Set the ListView style to show sub-item images lStyle = SendMessage(ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, _ ByVal 0&) lStyle = lStyle Or LVS_EX_SUBITEMIMAGES SendMessage ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, ByVal _ lStyle ' Change the ListItem's sub-item image With LV .Mask = LVIF_IMAGE .Item = li.Index - 1 .SubItem = 1 '1-based index of sub-item .Image = 1 '0-based index of list image End With SendMessage ListView1.hwnd, LVM_SETITEM, li.Index - 1, LV End Sub 'When run, this code will display a single ListItem with the first image as 'the Item 's icon and the second image as the sub-item's icon. |