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. How to avoid value repetition in the CListCtrl

How to avoid value repetition in the CListCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialhelp
6 Posts 4 Posters 8 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
    Murugan k
    wrote on last edited by
    #1

    Hi, I have insert the string value in the CListCtl using InsertItem method. For example. i have able to pupulate following value in the ClistCtl .My problem is how avoid repeted value that is 200. 100 200 200 200 kandly replay me. Thanks.

    N CPalliniC C 3 Replies Last reply
    0
    • M Murugan k

      Hi, I have insert the string value in the CListCtl using InsertItem method. For example. i have able to pupulate following value in the ClistCtl .My problem is how avoid repeted value that is 200. 100 200 200 200 kandly replay me. Thanks.

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      You can iterate through the list and remove duplicate ones no? Also there are useful stl algorithms like unique which works on a sorted list, so before inserting you can call unique on the list.

      Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

      M 1 Reply Last reply
      0
      • M Murugan k

        Hi, I have insert the string value in the CListCtl using InsertItem method. For example. i have able to pupulate following value in the ClistCtl .My problem is how avoid repeted value that is 200. 100 200 200 200 kandly replay me. Thanks.

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        Why don't you check before inserting? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • M Murugan k

          Hi, I have insert the string value in the CListCtl using InsertItem method. For example. i have able to pupulate following value in the ClistCtl .My problem is how avoid repeted value that is 200. 100 200 200 200 kandly replay me. Thanks.

          C Offline
          C Offline
          chandu004
          wrote on last edited by
          #4

          you can traverse thorough the list to see if the element you are going toinsert already exist or not. if it exsist dont insert. otherwise insert.

          -------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.

          1 Reply Last reply
          0
          • N Nibu babu thomas

            You can iterate through the list and remove duplicate ones no? Also there are useful stl algorithms like unique which works on a sorted list, so before inserting you can call unique on the list.

            Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

            M Offline
            M Offline
            Murugan k
            wrote on last edited by
            #5

            Hi Thomas, How can i call unique before inserting value to list. kindly can you clarify me. Thank.

            N 1 Reply Last reply
            0
            • M Murugan k

              Hi Thomas, How can i call unique before inserting value to list. kindly can you clarify me. Thank.

              N Offline
              N Offline
              Nibu babu thomas
              wrote on last edited by
              #6

              Murugan k wrote:

              How can i call unique before inserting value to list.

              You can use unique only if you have a std::list/vector/etc with you which instead you are inserting to a list control. But since you are directly inserting to the list control use CListCtrl::FindItem, if found don't insert. I guess this will help?

              Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com

              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