-
June 19th, 2002, 02:56 AM
#1
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.
-
June 19th, 2002, 04:23 AM
#2
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.
-
June 19th, 2002, 04:34 AM
#3
Handle LVN_ITEMCHANGED and then call GetSelectedCount()
to test for multiple selections.
Regards,
Prem
-
June 19th, 2002, 04:37 AM
#4
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
-
June 22nd, 2002, 12:17 AM
#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.
-
October 21st, 2008, 01:45 PM
#6
Re: CListCtrl selection
This is really nice. its really helpful. thanks.
-
October 21st, 2008, 01:59 PM
#7
Re: CListCtrl selection
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|