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 selections in List View (LVS)

multiple selections in List View (LVS)

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharphelptutorialquestion
7 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.
  • A Offline
    A Offline
    aafcls
    wrote on last edited by
    #1

    Hello! This is my first post on the Code Project, maybe you can help me. In my dialog box I have a list view and a check box. If the check box is unselected, the user should be able to select any list item they wish. However, if the check box is selected, and there are only two list items, I want both list items automatically selected as it is a requirement of my application (right now, the user has to Shift select both list items before proceeding, and I want to remove this ambiguity by having both required list items selected for them). However if there are more than two items in the list, there should be no automatic highlighting. That said, I'm not sure how to go about this in Visual C++ .NET. Any suggestions? Thank you. :)

    M 1 Reply Last reply
    0
    • A aafcls

      Hello! This is my first post on the Code Project, maybe you can help me. In my dialog box I have a list view and a check box. If the check box is unselected, the user should be able to select any list item they wish. However, if the check box is selected, and there are only two list items, I want both list items automatically selected as it is a requirement of my application (right now, the user has to Shift select both list items before proceeding, and I want to remove this ambiguity by having both required list items selected for them). However if there are more than two items in the list, there should be no automatic highlighting. That said, I'm not sure how to go about this in Visual C++ .NET. Any suggestions? Thank you. :)

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      See the FAQ: 4.10 How do I programmatically select an item in a list view control?[^]

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

      A 1 Reply Last reply
      0
      • M Michael Dunn

        See the FAQ: 4.10 How do I programmatically select an item in a list view control?[^]

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

        A Offline
        A Offline
        aafcls
        wrote on last edited by
        #3

        Mike, where the FAQ says: Here is how to select an item whose index is nItemToSelect: // MFC: wndYourList.SetItemState ( nItemToSelect, LVIS_SELECTED, LVIS_SELECTED ); does "index" refer to an actual number? for example, if I have 2 items in my list, would the first item be index "0", then index "1"? any others have alternative suggestions? (sorry, I am a novice)

        Z M 2 Replies Last reply
        0
        • A aafcls

          Mike, where the FAQ says: Here is how to select an item whose index is nItemToSelect: // MFC: wndYourList.SetItemState ( nItemToSelect, LVIS_SELECTED, LVIS_SELECTED ); does "index" refer to an actual number? for example, if I have 2 items in my list, would the first item be index "0", then index "1"? any others have alternative suggestions? (sorry, I am a novice)

          Z Offline
          Z Offline
          Zac Howland
          wrote on last edited by
          #4

          aafcls wrote:

          does "index" refer to an actual number? for example, if I have 2 items in my list, would the first item be index "0", then index "1"?

          Index refers to the item number, but it isn't necessarily in order (if you allow sorting your list items, it will be highly random). You should just need to call CListCtrl::GetItemCount to see how many items there are in the list and if there are 2 or fewer, use CListCtrl::GetNextItem with the default flags to get the item index. After that, use the index in your CListCtrl::SetItemState call. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

          1 Reply Last reply
          0
          • A aafcls

            Mike, where the FAQ says: Here is how to select an item whose index is nItemToSelect: // MFC: wndYourList.SetItemState ( nItemToSelect, LVIS_SELECTED, LVIS_SELECTED ); does "index" refer to an actual number? for example, if I have 2 items in my list, would the first item be index "0", then index "1"? any others have alternative suggestions? (sorry, I am a novice)

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Yes, item numbering starts at 0

            --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

            A 1 Reply Last reply
            0
            • M Michael Dunn

              Yes, item numbering starts at 0

              --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

              A Offline
              A Offline
              aafcls
              wrote on last edited by
              #6

              Thanks, this works. However, instead of selecting each item by index number, is there a way to "select all"? (instead of having to do individual SetItemState)

              M 1 Reply Last reply
              0
              • A aafcls

                Thanks, this works. However, instead of selecting each item by index number, is there a way to "select all"? (instead of having to do individual SetItemState)

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #7

                Pass -1 for the item index to set the state of all items at once.

                --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

                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