CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: CListCtrl

  1. #1
    Guest

    CListCtrl

    Hi,

    I am trying to do the following: If the user clicks anywhere on a CListCtrl (doesn't have to be the first column), the matching item should be selected. For this action, I am using code I found on codeguru's control section.

    Why isn't it working?

    void CPreislisteDlg::OnLButtonDown(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default

    CDialog::OnLButtonDown(nFlags, point);

    int index;
    point.x = 2;

    if((index = m_cPreisListe.HitTest(point, NULL)) != -1)
    {
    MessageBox("OK");
    m_cPreisListe.SetItemState(index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
    }
    }



    Thanks!


    Fox20



  2. #2
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    418

    Re: CListCtrl

    Hi,

    OnLButtonDown gives you the coordinates in coordinates relative to the dialog, but HitTest expects them to be relative to the CListCtrl. So you need to convert them with MapWindowPoints.

    But a better way will be to write a handler for the NM_CLICK message. It will give you not only the point where clicked, but also which item and subitem.


    Martin

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