Hi All
Could anyone help me, I need to get the position as a number of a selected Item in a listview.
Paul great product.
You need to loop through all items and check their selected state.
for(int x = 0; x< lv.GetCount(); x++)
{
if( lv.GetSel( x ))
break;
}
if(x < lv.GetCount())
//x = the selected item in the listview
else
//nothing is selected ot there are no items.
Cheers Paul.
The easiest way is to use the LVM_GETSELECTIONMARK message, that I don't know why is missing in the CListView class. This message is defined by Microsoft as LVM_FIRST + 66.
You can retrieve the handle of the ListView and use the API function SendMessageA:
SelMark = SendMessageA(hWndListView, LVM_GETSELECTIONMARK, 0, 0);
If SelMark = -1 it means that there is not selected item.
LVM_GETSELECTIONMARK does not work with earlier versions of the common control library. And it is meant to retrieve the last selected item, not the current one. I remember trying it on Win 98 and it always returned -1.
The proper way to do it, besides looping, is to send the message LVM_GETNEXTITEM message with the LVNI_SELECTED flag. Which is something I can add.
OK Added CListView::GetCurSel which returns the currently selected item in a single selection listview.
Quote
that I don't know why is missing in the CListView class
Because no one has asked for it...before now.
It is very cool seeing a new powerful language develop. The interactive of users and developer forming something really neat. It takes a great programmer/developer like Paul on one end and you guys on this end that know a lot too and adding your input.
Fun to watch and read it all even if lots of it doesn't make sense to me right now :)