Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21411

Adding items to a ListView with LVM_INSERTITEM: not working

$
0
0
I'm trying to add items to my listview using API.

The first item added works, but after that any additional item or subitem of the first shows up blank, as does the first if I scroll (the items are counted and the scrollbar indicates more items added). If I click the listview, VB crashes. I've checked around for examples, and I've seen several projects using it the exact same way, so I'm at a loss as to what I'm doing wrong.

Code:

Public Type LVITEM_S  ' LVITEM with pszText as string
  mask As Long
  iItem As Long
  iSubItem As Long
  state As Long
  stateMask As Long
  pszText As String
  cchTextMax As Long
  iImage As Long
  lParam As Long
#If (WIN32_IE >= &H300) Then
  iIndent As Long
  iGroupId As Long
  cColumns As Long
  puColumns As Long
#End If
End Type


lvi.iItem = lLVCnt
lvi.iImage = uSHFI.iIcon 'GetFileIconIndex(ParseFileOut(rfFile), SHGFI_SMALLICON)
lvi.pszText = rfFile.sFile & Chr$(0)
lvi.cchTextMax = Len(rfFile.sFile) + 1
lvi.lParam = lLVCnt
lvi.mask = LVIF_IMAGE Or LVIF_TEXT Or LVIF_PARAM
hr = SendMessage(lvSearch.hWnd, LVM_INSERTITEM, 0&, lvi)

The return from SendMessage is correct (returning a new item index, 0, 1, 2, etc). And all I did was remove .ListItems.Add and ListItem.image etc, so the code was working fine and nothing besides the actual item add part was changed. Using Common Control 5.0 LV on Win7 x64. Maybe I could go a different route and use a callback and LVM_GETDISPINFO, but this way seems to work for others. If anyone has any insight, it would be appreciated.

Viewing all articles
Browse latest Browse all 21411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>