I'm getting a strange error that has been giving me nothing but trouble for days! What I'm doing is, when my app recieves the WM_INITDIALOG message I setup my listview (setting the colors, and adding 2 columns) then after thats all done I invoke my AddListViewItem proc to add my defualt item. Everything works great until I try to insert another listview item doing it the exact same way (invoking my AddListViewItem proc) but later on, say when I click a button. But it only inserts the new item in the first column and leaves the 2nd column blank. I was wondering if anyone could point out a problem that might be causing this. Below the code is listed in order of being called.



SetupListView proc hWnd:HWND
LOCAL lvc:LV_COLUMN

; Get the listview handle and remember it
invoke GetDlgItem, hWnd, IDC_LISTVIEW
mov hListView, eax

; Enable the extended Listview style for full row select etc
invoke SendMessage, hListView, LVM_SETEXTENDEDLISTVIEWSTYLE, 0 , LVS_EX_FULLROWSELECT or LVS_EX_GRIDLINES

; Insert first column
mov lvc.imask, LVCF_TEXT or LVCF_WIDTH
mov lvc.pszText, offset lvcHeading1
mov lvc.lx, 165
invoke SendMessage, hListView, LVM_INSERTCOLUMN, 0, addr lvc

; Insert second column
mov lvc.pszText, offset lvcHeading2
mov lvc.lx, 163
invoke SendMessage, hListView, LVM_INSERTCOLUMN, 1, addr lvc

; Set the colors of the listview
RGB 0, 0, 0
invoke SendMessage, hListView, LVM_SETTEXTCOLOR, 0, eax
RGB 225, 225, 225
invoke SendMessage, hListView, LVM_SETBKCOLOR, 0, eax
RGB 225, 225, 225
invoke SendMessage, hListView, LVM_SETTEXTBKCOLOR, 0, eax
ret
SetupListView endp

SetupListView called: invoke SetupListView, hWnd


AddListViewItem proc pszItemText:DWORD, pszSubItemText:DWORD
local lvi:LV_ITEM
; Create a new item
mov lvi.imask, LVIF_TEXT + LVIF_PARAM
mov lvi.iSubItem, 0
mov eax, pszItemText
mov lvi.pszText, eax
invoke SendMessage, hListView, LVM_INSERTITEM, 0, addr lvi

; Set the subitem
mov lvi.imask, LVIF_TEXT
mov lvi.iSubItem, 1
mov eax, pszSubItemText
mov lvi.pszText, eax
invoke SendMessage, hListView, LVM_SETITEM, 0, addr lvi
ret
AddListViewItem endp

AddListViewItem called: invoke AddListViewItem, addr szAppTitle, addr szAppTitle


Thanks very much for any help you can provide!
Posted on 2001-12-06 11:41:19 by JamesE
JamesE,

if you're using a listbox with more than one column
To add a new item you have to use LVM_INSERTITEM message for example
I use to start from row 0 (item 0 = first row) and subItem 0(first column).




mov lvi.Item,0
mov lvi.SubItem,0
mov lvi.lParam,ebx
mov lvi.mask, LVIF_IMAGE or LVIF_PARAM
call SendMessageA, hListView, LVM_INSERTITEM, 0, offset lvi


(i use lparam for ordering in a next step, for item insertion now it's not important).
Now is added a new item with text set in the first column. In my specific case i've put an icon (IMAGE).

To add another text to same item but in another column you have to use subItem and LVM_SETITEM message (that correspond to the column):



mov eax,offset MyText
mov lvi.imask,LVIF_TEXT
mov lvi.itpszText,eax
mov lvi.itItem,ebx
inc lvi.itSubItem 'before was 0 (first column)
call SendMessageA, hListView, LVM_SETITEM, 0, offset lvi


Now, incrementing Item to 1 you can add a new item.
The only way to add subItems iseems calling SendMessageA for every subItem to add.

In my site there is a proggy: bbook, an easy address book that use a ListView with many columns. Take a look to see how i've done it.
Hope it can help.

Bye B7
Posted on 2001-12-06 13:39:41 by Bit7
try this:


AddListViewItem proc pszItemText:DWORD, pszSubItemText:DWORD
local lvi:LV_ITEM
; Create a new item
mov lvi.imask, LVIF_TEXT + LVIF_PARAM
mov lvi.iItem, 0
mov lvi.iSubItem, 0
mov eax, pszItemText
mov lvi.pszText, eax
mov lvi.cchTextMax,eax

invoke SendMessage, hListView, LVM_INSERTITEM, 0, addr lvi

; Set the subitem
mov lvi.imask, LVIF_TEXT
mov lvi.iSubItem, 1
mov eax, pszSubItemText
mov lvi.pszText, eax
mov lvi.cchTextMax, eax
invoke SendMessage, hListView, LVM_SETITEM, 0, addr lvi
ret
AddListViewItem endp

AddListViewItem called: invoke AddListViewItem, addr szAppTitle, addr szAppTitle
Posted on 2001-12-06 22:38:02 by smurf
Thanks Smurf,

Works great now! Simple little error can't believe I missed it.

:alright:
Posted on 2001-12-07 08:21:52 by JamesE