Getting row number when double clicking listview control
Hi, I try to get the row number when clicking listview control by using HitTest(), but it doesn't.
I put the listview control on a dialog bar. Does it matter?
nIndex always returns -1 :(
void CMainFrame::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CListCtrl* pListCtrl = (CListCtrl*)m_wndDlgBar.GetDlgItem(IDC_LIST2);
DWORD dwPos = ::GetMessagePos() ;
CPoint point ((int) LOWORD (dwPos), (int) HIWORD (dwPos)) ;
pListCtrl->ScreenToClient (&point) ;
int nIndex ;
if ((nIndex = pListCtrl->HitTest (point)) != -1)
{
CString string = pListCtrl->GetItemText (nIndex, 0) ;
MessageBox(string) ;
}
*pResult = 0;
}
Re: Getting row number when double clicking listview control
I have do it by myself... ^_^
void CMainFrame::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CListCtrl* pListCtrl = (CListCtrl*)m_wndDlgBar.GetDlgItem(IDC_LIST2);
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
CPoint point(pNMListView->ptAction);
int row ;
if ((row = pListCtrl->HitTest (point)) != -1)
{
CString sTmp;
sTmp.Format("Column clicked: %d, Row clicked: %d",
pNMListView->iSubItem, row);
MessageBox(sTmp);
}
*pResult = 0;
}
Re: Getting row number when double clicking listview control
I did it by catching WM_LBUTTONDBLCLK message. It may be not the good way.
void CMyListView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CListCtrl* pListCtrl=&GetListCtrl();
int nIndex=pListCtrl->HitTest(point);
CString str;
str.Format("Hit on item No. %d",nIndex);
AfxMessageBox(str);
CListView::OnLButtonDblClk(nFlags, point);
}