Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Multiple selection in list control

Multiple selection in list control

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hemlat
    wrote on last edited by
    #1

    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.

    S 1 Reply Last reply
    0
    • H hemlat

      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.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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

      H 1 Reply Last reply
      0
      • S Stuart Dootson

        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

        H Offline
        H Offline
        hemlat
        wrote on last edited by
        #3

        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?

        S D 2 Replies Last reply
        0
        • H hemlat

          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?

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • H hemlat

            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?

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups