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

    Detecting which subitem has been clicked in a listcontrol

    I'm using VC++ 5.0, and I need to detect which subitem has been clicked in a list control. The method HitTest() only returns the item. A Method would be to test in which subitem range the click fall into but there is no way to get the listctrl position (GetOrigin() does not work in report mode).

    So how do you detect the subitem on which the user click ?


  2. #2
    Guest

    Re: Detecting which subitem has been clicked in a listcontrol

    A solution that works in alone or multiple selection mode:

    int length = m_list.GetItemCount();

    for (int i = 0; i < length;i++) {
    if (m_list.GetItemState(i, LVIS_SELECTED)) {
    // do what you want with the selected line
    // use the index i for access to the object
    // example: m_list.GetItemText( i, 0, szDest, 16 );
    }
    }

    There is another solution for the one-select mode, but I've forgotten it. This one works well.

    Pascal.



  3. #3
    Guest

    Re: Detecting which subitem has been clicked in a listcontrol

    when you catch the OnClick event, you get a NMHDR* var as one of your parameters, you can cast this to a NM_LISTVIEW*, and it has an iSubItem member that should tell you which subitem was clicked (I think).

    something like

    void
    CMyListCtl::OnClick (NMHDR* pNMHDR, LRESULT* pResult)
    {
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    int iSubItem = pNMListView->iSubItem;
    }




    --michael


  4. #4
    Join Date
    Apr 1999
    Posts
    13

    Re: Detecting which subitem has been clicked in a listcontrol

    Hello!
    You can use method CListCtrl::SubItemHitTest() if you are using comctl32.dll version >= 4.70 (it comes with IE3.0). See MSDN for details.
    Dmitry Barashev.


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