How to get the selected item in a List Ctrl
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
Re: How to get the selected item in a List Ctrl
Try with CListBox
it has a member function SetCurSel()
consider and the other funcs
Re: How to get the selected item in a List Ctrl
try:
void xxx::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW * pNMListView = (NM_LISTVIEW*) pNMHDR;
long Index = pNMListView->iItem;
...
Re: How to get the selected item in a List Ctrl
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.
Re: How to get the selected item in a List Ctrl
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
Re: How to get the selected item in a List Ctrl
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
Re: How to get the selected item in a List Ctrl
try this.
CListCtrl::GetNextItem(-1, LVNI_ALL | LVNI_SELECTED)
hope this help
Re: How to get the selected item in a List Ctrl
If you know the where the item is in the CListCtrl, how do you retrieve the LVITEM struct of it?
Re: How to get the selected item in a List Ctrl
int nSelected;
nSelected = m_WndLis.GetNextItem(-1, LVNI_FOCUSED|LVNI_SELECTED);
if(nSelected==-1)//mean no selected
else get item no in nSeleceted