May 08, 2024, 01:15:29 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


ListView get selected item number

Started by Pip1957, July 16, 2006, 08:49:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Pip1957

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.

Ionic Wind Support Team

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.
Ionic Wind Support Team

Pip1957


JR

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.

Ionic Wind Support Team

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.
Ionic Wind Support Team

Ionic Wind Support Team

OK Added CListView::GetCurSel which returns the currently selected item in a single selection listview.

Ionic Wind Support Team

Ionic Wind Support Team

Quote
that I don't know why is missing in the CListView class

Because no one has asked for it...before now.
Ionic Wind Support Team

kryton9

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 :)