Click to See Complete Forum and Search --> : How to get the selected item in a List Ctrl


Sandeep Pendharkar
April 5th, 1999, 03:41 AM
Hi,
I've a CListCtrl derived control embedded in Form View. How do i get the selected item in the list control on a left button click. Note that I can trap the notification message NM_CLICK but how does one proceed from there!!

TIA
Sandeep Pendharkar

ric
April 5th, 1999, 04:47 AM
Try with CListBox
it has a member function SetCurSel()
consider and the other funcs

April 5th, 1999, 04:58 AM
try:
void xxx::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW * pNMListView = (NM_LISTVIEW*) pNMHDR;
long Index = pNMListView->iItem;
...

yash
April 5th, 1999, 05:03 PM
HI ,
try this code !

void CMyDialog::OnDblclkDitContentsList(NMHDR* pNMHDR, LRESULT* pResult)
{
CString SelectedJobID ;
int Index = 0 ;

while( 1)
{
if ( m_DITContents.GetItemState( Index , LVIS_SELECTED ) == LVIS_SELECTED )
break ;
else
Index++ ;
}

// index now gives the selected row .
// get the Required column say column 4th.
SelectedJobID = m_DITContents.GetItemText ( Index , 3 ) ;
......


Hope this helps .
Good Luck.
Yash.

Magnus Eklof
April 8th, 1999, 03:49 AM
Of course this is what you should do ;)

int index = GetNextItem(-1, LVNI_SELECTED);

and beware that a message like NM_DBLCLK can be trapped before the item is set as selected, you can get strange behaviour if you select one node (left-click) then dclick on another node, and then get the index of the selected item, it will not be the one you double clicked...

/Magnus

Daren Chandisingh
April 8th, 1999, 04:06 AM
CListCtrl::GetFirstSelectedItemPosition
POSITION GetFirstSelectedItemPosition( ) const;

CListCtrl::GetItem
BOOL GetItem( LVITEM* pItem ) const;



POSITION pos = list.GetFirstSelectedItemPosition( )
LVITEM lvItem;
lvItem.iItem = pos;
list.GetItem(&lvItem);



(Never tried this, but it seems reasonable.)



--
Daren Chandisingh

Candan
April 8th, 1999, 04:51 AM
try this.

CListCtrl::GetNextItem(-1, LVNI_ALL | LVNI_SELECTED)

hope this help

nouser
July 4th, 1999, 03:01 AM
If you know the where the item is in the CListCtrl, how do you retrieve the LVITEM struct of it?

abrar
July 4th, 1999, 06:29 AM
int nSelected;
nSelected = m_WndLis.GetNextItem(-1, LVNI_FOCUSED|LVNI_SELECTED);
if(nSelected==-1)//mean no selected
else get item no in nSeleceted