Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
case WM_NOTIFY:
    LPNMHDR hdr;
    LPNMLISTVIEW nlv;
     
    hdr=(LPNMHDR)lParam;
    nlv=(LPNMLISTVIEW)lParam;
    if(hdr->hwndFrom==hMlb)
    {
        switch(hdr->code)
        {
        case LVN_ITEMCHANGED:
            if(nlv->uChanged==LVIF_STATE&&nlv->uNewState==(LVIS_SELECTED|LVIS_FOCUSED))
            {
            
                LI.iItem=nlv->iItem;
                LI.iSubItem=1;
                ListView_GetItem(hMlb,&LI);
                
                ListView_GetItemText(hMlb,nlv->iItem,1,buf,20);
                SetDlgItemText(hwnd,IDM_mtitle,buf);
            }
            return TRUE;
        }
    }
    break;




Actually, subitem was selectable in listview. But, after I added above code, subitem changed into non-selectable line. What I gonna do is that set text in editbox(hMlb) when user click subitem '1'. what's wrong with this source code?
Posted
Updated 29-Nov-12 2:05am
v2
Comments
Richard MacCutchan 29-Nov-12 8:15am    
What's wrong with this source code? Well it needs better use of spaces between operators and operands; other than that I have no idea. Maybe you could give us some more clues.

1 solution

If the code above is complete then it looks like you have not specified the mask before calling ListView_GetItem. This, together with the fact that you haven't "ZeroMemoried" the LI variable means that mask can be anything. If it happens that mask contains LVIF_TEXT flag by any chance then you may easily corrupt your memory.

So, the solution in your case will be to comment these three lines like this (what's the purpose of them anyway?):

C++
//LI.iItem=nlv->iItem;
//LI.iSubItem=1;
//ListView_GetItem(hMlb,&LI);


If you really need to call ListView_GetItem you need to specify mask. It is also always a good idea to ZeroMemory the C structs before using them.

On the side note, it looks like that you assigning nlv=(LPNMLISTVIEW)lParam; too early. I recommend you moving this line further down after case LVN_ITEMCHANGED: line.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900