IonicWind Software

Aurora Compiler => GUI => Topic started by: Pip1957 on July 16, 2006, 08:49:20 AM

Title: ListView get selected item number
Post by: Pip1957 on July 16, 2006, 08:49:20 AM
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.
Title: Re: ListView get selected item number
Post by: Ionic Wind Support Team on July 16, 2006, 09:00:15 AM
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.
Title: Re: ListView get selected item number
Post by: Pip1957 on July 16, 2006, 09:10:12 AM
Cheers Paul.
Title: Re: ListView get selected item number
Post by: JR on July 16, 2006, 10:21:23 AM
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.
Title: Re: ListView get selected item number
Post by: Ionic Wind Support Team on July 16, 2006, 10:44:59 AM
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.
Title: Re: ListView get selected item number
Post by: Ionic Wind Support Team on July 16, 2006, 10:55:24 AM
OK Added CListView::GetCurSel which returns the currently selected item in a single selection listview.

Title: Re: ListView get selected item number
Post by: Ionic Wind Support Team on July 16, 2006, 10:56:05 AM
Quote
that I don't know why is missing in the CListView class

Because no one has asked for it...before now.
Title: Re: ListView get selected item number
Post by: kryton9 on July 16, 2006, 01:38:59 PM
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 :)