views:

232

answers:

1

I try to create list view item like explorer . I want to get the selected item when I double click on it .

So I can use it to get the path and find file to display . I can do it in treeview by senddlgmessage. But it looks like it doesn't work on listview .

+1  A: 

If you are just using a raw ListView control in C++, you need to do something like this:

// Get the first selected item
int iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
while (iPos != -1) {
    // iPos is the index of a selected item
    // do whatever you want with it

    // Get the next selected item
    iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED);
}
Grammarian
Thanks so much . I read your profile, i'm surprised and really grateful to meet a guru like you :)
nXqd
one more question: I get the index, what should I do if I want to get its text ?
nXqd
Use ListView_GetItem macro, passing in a LVITEM structure with iItem set to the index of the item you are interested in. Just out of curiosity, why are you doing this in raw winapi? mfc is a big help if you have to use c++? WinForms is an even bigger help if you can use c#
Grammarian