CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2002
    Location
    INDIA
    Posts
    3

    Angry CListCtrl selection

    Hi All,
    I am using CListCtrl item in Report view mode with multiple columns and multiple selection is also allowed in the CListCtrl.
    I want to enable 2 controls when a single row is selected and enable 1 control and disable the other one when more than one row is selected.
    I have used ON_NOTIFY(NM_CLICK, listCtrl, onClick); and in the OnClick() method i am able to disable/enable the controls. Fine.
    But i don't know how to enable/disable the controls when the user selects the rows using the keyboard keys like Up Arrow, Down Arrow,...
    Is there any notification available in MFC when the row selection is highlighted in the list ctrl?

    Thanks in advance.
    Please help.

    Prem.

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    40
    You can trap key presses in the control using the LVN_KEYDOWN message. I guess you can then call your enable/disable code from here to give your buttons the correct state.

  3. #3
    Join Date
    Oct 2000
    Location
    India
    Posts
    489
    Handle LVN_ITEMCHANGED and then call GetSelectedCount()
    to test for multiple selections.
    Regards,
    Prem

  4. #4
    Join Date
    Oct 2001
    Location
    Dublin, Eire
    Posts
    880
    What you need is just to detect when the selection changes. Then you get the number of selected items and you kknow if you need to enable one or two controls.

    I think there is an event to detect a change in the selection (whatever mean is used to change the selection: mouse click, keyboard or progam selection).
    Elrond
    A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
    -- George Steiner

  5. #5
    Join Date
    Jun 2002
    Location
    Zagreb, Croatia
    Posts
    5
    Hi. To catch user selection changes in CListCtrl create an event handler trough class wizard for LVN_ITEMCHANGED and use the following code:


    Code:
    void CAnimDialog::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
    {
    	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    
    	if( pNMListView->uNewState & LVIS_SELECTED )
    	{
    		int selectedItem = pNMListView->iItem;
    	}
    	
    	*pResult = 0;
    }
    Note that U have to check LVIS_SELECTED because when selection chage occurs not one LVN_ITEMCHANGED event is generated, but a few ones, for items that have ben deselected, etc. So if u want to find out which item was deselected you would simply chage pNMListView->uNewState to pNMListView->uOldState.

    Hope I helped you.

  6. #6
    Join Date
    May 2006
    Location
    India
    Posts
    22

    Thumbs up Re: CListCtrl selection

    This is really nice. its really helpful. thanks.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CListCtrl selection

    Quote Originally Posted by raj1to0
    This is really nice. its really helpful. thanks.
    It's been over six years since KizUnusuAll posted here. He probably won't see your reply.

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