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

    MFC: ClistCtrl::GetSelectedColumn

    Hi,

    I'm currently using a CListCtrl for my application, thus i would like to sort items when the user click on an column header.

    I manage to detect the click action, but i don't know how to retrieve the selected column...the msdn talk about a GetSelectedColumn method in the CListCtrl class, that's cool but when i type the call to this method and i compile i've an:

    :\myprog\mator\DialogPlayer.cpp(225) : error C2039: 'GetSelectedColumn' : is not a member of 'CListCtrl'
    c:\program files\microsoft visual studio\vc98\mfc\include\afxcmn.h(177) : see declaration of 'CListCtrl'

    how can i do ?

    Thanks for help !

  2. #2
    Join Date
    Jul 2002
    Location
    St. Louis, MO
    Posts
    484
    PHP Code:
    ON_NOTIFY(LVN_COLUMNCLICKIDC_MYLISTOnLvnColumnclickMyList)

    void MyView::OnLvnColumnclickMyList(NMHDR *pNMHDRLRESULT *pResult)
    {
        
    LPNMLISTVIEW pNMLV reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

        
    // pNMLV->iSubItem is the column index
        
    _myList.SortItems(CompareFunpNMLV->iSubItem);

        *
    pResult 0;


  3. #3
    Join Date
    Apr 2003
    Posts
    2
    Yeah thanx a lot !

  4. #4
    Join Date
    Apr 1999
    Posts
    3,585
    To detect a click on the column header, you can respond to a HDN_ITEMCLICK message. It is sent via ON_NOTIFY. For example,

    ON_NOTIFY( HDN_ITEMCLICK, 0, OnClickListColumnHdr )

    The handler appears like this:

    void CMyDlg::OnClickListColumnHdr(NMHDR* pNotifyStruct, LRESULT* pResult)

    pNotifyStruct contains a member called 'iItem' that indicates the column that was clicked.
    Gort...Klaatu, Barada Nikto!

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