Multiple selection in list control
-
Hi, I have created MFC application.I have used ListControl in it.I need to use multiple selection in ListControl.I have made single selection false.But it does not work.I have added following line.
m_lcSample.ModifyStyle(LVS_SINGLESEL, 0);
But it does not work.Can anyone help me.
-
Hi, I have created MFC application.I have used ListControl in it.I need to use multiple selection in ListControl.I have made single selection false.But it does not work.I have added following line.
m_lcSample.ModifyStyle(LVS_SINGLESEL, 0);
But it does not work.Can anyone help me.
All I can do is confirm that your code is correct and works for me - one other thing, though, the documentation for
LVS_SINGLESEL
states By default, multiple items may be selected, so you shouldn't need to do that anyway, unless you've explicitly selected "Single Selection" for the control in the dialog editor.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
All I can do is confirm that your code is correct and works for me - one other thing, though, the documentation for
LVS_SINGLESEL
states By default, multiple items may be selected, so you shouldn't need to do that anyway, unless you've explicitly selected "Single Selection" for the control in the dialog editor.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Thanks for your reply.If I select muiltiple items with "ctrl" button then I can able to do multiple selection. But for ListBox this is not the case. Previously I thought I can do multiple selection without "ctrl" button as Listbox.Can I do that?
Oh, I see (I think) - you want to add to the selection whenever you click on an item? Nah, can't do that with a standard list control. However, I'm sure you could use the notifications that a list control sends (LVN_ITEMCHANGING, LVN_ITMECHANGED, NM_CLICK) to implement your selection logic. e.g. here's some code handling notifications from a list control (list_). This inverts a particular item's selection when it's clicked on, not affecting any other control's selection state. canChangeSel_ is a bool member of the dialog, and is used to tell the LVN_ITEMCHANGING handler if it can allow selection changes or not.
void CaaaDlg::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE itemActivate = (LPNMITEMACTIVATE)pNMHDR;
const int hit = list_.HitTest(LPNMITEMACTIVATE(pNMHDR)->ptAction);
if (hit != -1)
{
canChangeSel_ = true;
list_.SetItemState(hit, ~(list_.GetItemState(hit, LVIS_SELECTED)), LVIS_SELECTED);
canChangeSel_ = false;
}
}
void CaaaDlg::OnItemChangingList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pLV = LPNMLISTVIEW(pNMHDR);
*pResult = FALSE;
if ((pLV->uChanged&LVIF_STATE) && LVIS_SELECTED==((pLV->uNewState^pLV->uOldState)&LVIS_SELECTED))
*pResult = canChangeSel_?FALSE:TRUE;
}Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Thanks for your reply.If I select muiltiple items with "ctrl" button then I can able to do multiple selection. But for ListBox this is not the case. Previously I thought I can do multiple selection without "ctrl" button as Listbox.Can I do that?
hemlat wrote:
But for ListBox this is not the case.
For a listbox, you must send it a
LBS_MULTIPLESEL
message."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons