CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    34

    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;
    }





  2. #2
    Join Date
    May 1999
    Posts
    34

    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;
    }





  3. #3
    Join Date
    May 1999
    Posts
    22

    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);
    }



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured