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. Multi/Single selection in a ListBox

Multi/Single selection in a ListBox

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 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.
  • M Offline
    M Offline
    magesh
    wrote on last edited by
    #1

    I have a dialog with a listbox. For some invocations of the dialog, I want the listbox to be multi-selection and for other invocations, the listbox should be single-select. In OnInitDialog(), I used ModifyStyle() to change the selection style. But this did not work. Is there a solution without subclassing CListBox?

    D 1 Reply Last reply
    0
    • M magesh

      I have a dialog with a listbox. For some invocations of the dialog, I want the listbox to be multi-selection and for other invocations, the listbox should be single-select. In OnInitDialog(), I used ModifyStyle() to change the selection style. But this did not work. Is there a solution without subclassing CListBox?

      D Offline
      D Offline
      Dmitriy
      wrote on last edited by
      #2

      There are 2 possible ways - 1) Derive your class from CListBox with multiselect style and handle selection event (mouse and keyboard) depends on the mode you have - allowing or dissallowing to select more then 1 item. 2) Every time you changing multiselect style - recreate control.

      M 1 Reply Last reply
      0
      • D Dmitriy

        There are 2 possible ways - 1) Derive your class from CListBox with multiselect style and handle selection event (mouse and keyboard) depends on the mode you have - allowing or dissallowing to select more then 1 item. 2) Every time you changing multiselect style - recreate control.

        M Offline
        M Offline
        magesh
        wrote on last edited by
        #3

        I did not make myself sufficiently clear. I have a list box in a dialog. Depending on an argument to the constructor of the dialog, I want to make this list box either single selection or multi-selection. However, once the selection style is set, It will not change for till the dialog is dismissed. In the resource editor, I'll set selection type to be 'single selection'. Depending on the argument to the constructor, I want to modify the selection type to 'Multi-Selection'. Is there a simple way of doing this without recreating the ctrl or deriving a class from CListBox. I tried ModifyStyle(0, LBS_MULTIPLESEL) in the OnInitDialog() of the dialog. This did not work. Hence this post.

        D 1 Reply Last reply
        0
        • M magesh

          I did not make myself sufficiently clear. I have a list box in a dialog. Depending on an argument to the constructor of the dialog, I want to make this list box either single selection or multi-selection. However, once the selection style is set, It will not change for till the dialog is dismissed. In the resource editor, I'll set selection type to be 'single selection'. Depending on the argument to the constructor, I want to modify the selection type to 'Multi-Selection'. Is there a simple way of doing this without recreating the ctrl or deriving a class from CListBox. I tried ModifyStyle(0, LBS_MULTIPLESEL) in the OnInitDialog() of the dialog. This did not work. Hence this post.

          D Offline
          D Offline
          Dmitriy
          wrote on last edited by
          #4

          "Depending on an argument to the constructor of the dialog..." Well, if you have dialog on the resource it will have the styles specified in resource editor, how can you change it? It doesnot create dialog like window. It loads it from the resource. Well, another option - create 2 dialogs in resource editor with different styles and load appropriate dialog from the resource.

          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