News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

listview problem(not inserting an item correctly)

Started by low_coder, September 06, 2009, 02:40:21 PM

Previous topic - Next topic

low_coder

when the user doubleclicks the listview item (under ".if [edi.NMHDR].code == NM_DBLCLK"), my app has to insert a new item which is "1" under "a" column and "1" under "b" column into another listview (the down one). it seems simple, but it does not work as it has to.
pls help if u can.
app and source in the attachment.

qWord

hi,

what about this:

 

LOCAL lvhti:LV_HITTESTINFO
LOCAL pt:POINT
LOCAL buffer[256]:BYTE
LOCAL iSubItem:DWORD
....
              .if [edi.NMHDR].code == NM_DBLCLK
                   
                    ; get item index
                    invoke GetCursorPos,ADDR pt
                    invoke ScreenToClient,[edi].NMHDR.hwndFrom,ADDR pt
                    m2m lvhti.pt.x,pt.x
                    m2m lvhti.pt.y,pt.y
                    invoke SendMessage,[edi].NMHDR.hwndFrom,LVM_HITTEST,0,ADDR lvhti                   
                    .if eax != -1
                        push esi
                        push edi
                        invoke SendDlgItemMessage,hDlg,IDC_LSV2,LVM_GETITEMCOUNT,0,0
                        mov esi,eax

                        mov lvi.imask,0
                        mov lvi.iItem,eax
                        mov lvi.iSubItem,0
                        invoke SendDlgItemMessage,hDlg,IDC_LSV2,LVM_INSERTITEM,0,ADDR lvi
                                           
                        ; was a subtitem clicked?
                        invoke SendMessage,[edi].NMHDR.hwndFrom,LVM_GETCOLUMNWIDTH,0,0
                        .if  pt.x < eax     ;double-click in column 1
                            mov iSubItem,0
                        .else               ;double-click in column 2
                            mov iSubItem,1                         
                        .endif
                       
                        ;shift all items in column down (by one)
                        mov edi,esi
                        sub edi,1
                        m2m lvi.iSubItem,iSubItem
                        .while SDWORD ptr edi >= 0
                            mov lvi.imask,LVIF_TEXT
                            mov lvi.iItem,edi
                            lea eax,buffer
                            mov lvi.pszText,eax
                            mov lvi.cchTextMax,SIZEOF buffer
                            invoke SendDlgItemMessage,hDlg,IDC_LSV2,LVM_GETITEM,0,ADDR lvi
                            mov lvi.iItem,esi
                            invoke SendDlgItemMessage,hDlg,IDC_LSV2,LVM_SETITEM,0,ADDR lvi
                            dec edi
                            dec esi                     
                        .endw                       
                       
                        ; set item at top
                        mov lvi.imask, LVIF_TEXT
                        mov lvi.iItem,0
                        mov lvi.pszText, offset strONE
                        invoke SendDlgItemMessage,hDlg,IDC_LSV2,LVM_SETITEM,0,ADDR lvi
                       
                        pop edi
                        pop esi
                    .endif
                .endif

regards, qWord
FPU in a trice: SmplMath
It's that simple!

low_coder

thx, but i think u misunderstood me. i just need to insert a new item with a subitem after the prevous one by incrementing the dwRow value which is used by lvi.iItem into second listview whenever the user doubleclicks on the first listview. the code u've offered is too complicated for such a simple action.

qWord

dwRow is a locale variable - declare it in .data-section
FPU in a trice: SmplMath
It's that simple!

low_coder