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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ListBox

ListBox

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

    I'm dumping data in a listbox using a loop. I would like the listbox to display the data after each iteration as oppose to after the loop is over, how do I do that?

    CPalliniC C K H 4 Replies Last reply
    0
    • C C NewBe

      I'm dumping data in a listbox using a loop. I would like the listbox to display the data after each iteration as oppose to after the loop is over, how do I do that?

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      Threads?

      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

      In testa che avete, signor di Ceprano?

      C 1 Reply Last reply
      0
      • C C NewBe

        I'm dumping data in a listbox using a loop. I would like the listbox to display the data after each iteration as oppose to after the loop is over, how do I do that?

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        If you do that in one single thread, the UI won't be able to process messages anymore (because the main thread is busy in your loop). This way, it will freeze and process the messages only when you exit the loop. The way to solve this problem is either to create a worker thread that will send a message to the GUI each time a new item should be added in the list, or you can extract messages yourself from the queue and process them (GetMessage and DispatchMessage, see here[^] for some info).

        Cédric Moonen Software developer
        Charting control [v1.3]

        1 Reply Last reply
        0
        • CPalliniC CPallini

          Threads?

          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

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

          I'm new to mfc...can you give me a kick start? also, would using a different control be better?

          CPalliniC 1 Reply Last reply
          0
          • C C NewBe

            I'm dumping data in a listbox using a loop. I would like the listbox to display the data after each iteration as oppose to after the loop is over, how do I do that?

            K Offline
            K Offline
            krmed
            wrote on last edited by
            #5

            Another option is after you add each string to the listbox, call the UpdateWindow:

            m_pMyListBox->AddString(_T("Whatever string"));
            m_pMyListBox->UpdateWindow();

            The UpdateWindow bypasses the normal message loop, so you can update that way. Hope that helps.

            Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

            C 1 Reply Last reply
            0
            • C C NewBe

              I'm new to mfc...can you give me a kick start? also, would using a different control be better?

              CPalliniC Online
              CPalliniC Online
              CPallini
              wrote on last edited by
              #6

              Please detail your problem. For instance, if your need to represent a very large amount of data, a virtual list control [^] maybe an option. :)

              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

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • K krmed

                Another option is after you add each string to the listbox, call the UpdateWindow:

                m_pMyListBox->AddString(_T("Whatever string"));
                m_pMyListBox->UpdateWindow();

                The UpdateWindow bypasses the normal message loop, so you can update that way. Hope that helps.

                Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

                C Offline
                C Offline
                C NewBe
                wrote on last edited by
                #7

                Karl, UpdateWindow has solved my problem...... Thanks How do I close this thread?

                K CPalliniC 2 Replies Last reply
                0
                • C C NewBe

                  Karl, UpdateWindow has solved my problem...... Thanks How do I close this thread?

                  K Offline
                  K Offline
                  krmed
                  wrote on last edited by
                  #8

                  Glad I could be of assistance. I don't know how you mark a thread as completed or resolved. Perhaps someone else knows.

                  Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

                  1 Reply Last reply
                  0
                  • C C NewBe

                    Karl, UpdateWindow has solved my problem...... Thanks How do I close this thread?

                    CPalliniC Online
                    CPalliniC Online
                    CPallini
                    wrote on last edited by
                    #9

                    C++NewBe wrote:

                    How do I close this thread?

                    Don't bother about, anyway you can modify the OP title (maybe adding [PROBLEM SOLVED] to the title). :)

                    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

                    In testa che avete, signor di Ceprano?

                    1 Reply Last reply
                    0
                    • C C NewBe

                      I'm dumping data in a listbox using a loop. I would like the listbox to display the data after each iteration as oppose to after the loop is over, how do I do that?

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #10

                      You cna use of CListCtrl instead CListBox that is better.

                      D 1 Reply Last reply
                      0
                      • H Hamid Taebi

                        You cna use of CListCtrl instead CListBox that is better.

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

                        Exactly how does that solve the problem?

                        "Love people and use things, not love things and use people." - Unknown

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        H 1 Reply Last reply
                        0
                        • D David Crow

                          Exactly how does that solve the problem?

                          "Love people and use things, not love things and use people." - Unknown

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          H Offline
                          H Offline
                          Hamid Taebi
                          wrote on last edited by
                          #12

                          I think listctl is bette than listbox and I think its better to try with listctrl so I said ctrl is better and its not direct his answer.

                          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