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#
  4. How to load 100,000 list view items without application freeze?

How to load 100,000 list view items without application freeze?

Scheduled Pinned Locked Moved C#
tutorialquestion
51 Posts 18 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.
  • L Lost User

    Change your design and use VirtualMode[^] to allow fast drawing of the ListView irrespective of where in the view you are positioned.

    I must get a clever new signature for 2011.

    C Offline
    C Offline
    Chesnokov Yuriy
    wrote on last edited by
    #11

    ok, I may try that in the end

    Чесноков

    1 Reply Last reply
    0
    • L Luc Pattyn

      Hi, here are some ideas for you: 1. having thousands of items in any Control does not make for a good user interface. 2. list oriented Controls will relayout and/or repaint themselves after every addition. it is wise to use AddRange rather than Add, and sometimes surround the entire operation with SuspendLayout/ResumeLayout. 3. if obtaining the items takes a while, it often helps to build a collection of items to be added to a list Control in a generic list, then add the list's content to the Control. The former can be performed on any thread, the latter obviously needs to be executed by the main thread. 4. some Controls have a "virtual mode" where one only needs to provide items when they become visible. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      modified on Monday, January 31, 2011 10:26 AM

      C Offline
      C Offline
      Chesnokov Yuriy
      wrote on last edited by
      #12

      1. log events with time column are easy to scroll 2. I tried to hide listview during items addition and then show it again, that increased performance, I will try yours methods 3. no, it does not, objects are already in the generic list with public methods e.g. time, message, keyword etc... the list view is in details view with columns to each field 4. that is not agreeble compared to 2.

      Чесноков

      L 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, here are some ideas for you: 1. having thousands of items in any Control does not make for a good user interface. 2. list oriented Controls will relayout and/or repaint themselves after every addition. it is wise to use AddRange rather than Add, and sometimes surround the entire operation with SuspendLayout/ResumeLayout. 3. if obtaining the items takes a while, it often helps to build a collection of items to be added to a list Control in a generic list, then add the list's content to the Control. The former can be performed on any thread, the latter obviously needs to be executed by the main thread. 4. some Controls have a "virtual mode" where one only needs to provide items when they become visible. :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        modified on Monday, January 31, 2011 10:26 AM

        C Offline
        C Offline
        Chesnokov Yuriy
        wrote on last edited by
        #13

        Luc Pattyn wrote:

        . it is wise to use AddRange rather than Add, and

        It will need to create a list of ListViewItems. Will it be faster than reporting from background worker item by item?

        Чесноков

        1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, here are some ideas for you: 1. having thousands of items in any Control does not make for a good user interface. 2. list oriented Controls will relayout and/or repaint themselves after every addition. it is wise to use AddRange rather than Add, and sometimes surround the entire operation with SuspendLayout/ResumeLayout. 3. if obtaining the items takes a while, it often helps to build a collection of items to be added to a list Control in a generic list, then add the list's content to the Control. The former can be performed on any thread, the latter obviously needs to be executed by the main thread. 4. some Controls have a "virtual mode" where one only needs to provide items when they become visible. :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          modified on Monday, January 31, 2011 10:26 AM

          C Offline
          C Offline
          Chesnokov Yuriy
          wrote on last edited by
          #14

          Luc Pattyn wrote:

          sometimes surround the entire operation with SuspendLayout/ResumeLayout

          that is significantly slower than hiding the control

          Чесноков

          1 Reply Last reply
          0
          • C Chesnokov Yuriy

            1. log events with time column are easy to scroll 2. I tried to hide listview during items addition and then show it again, that increased performance, I will try yours methods 3. no, it does not, objects are already in the generic list with public methods e.g. time, message, keyword etc... the list view is in details view with columns to each field 4. that is not agreeble compared to 2.

            Чесноков

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #15

            For logging I recommend a ListBox, it will easily handle thousands of lines per second. See here[^]. :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            C 1 Reply Last reply
            0
            • L Luc Pattyn

              For logging I recommend a ListBox, it will easily handle thousands of lines per second. See here[^]. :)

              Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

              C Offline
              C Offline
              Chesnokov Yuriy
              wrote on last edited by
              #16

              I need to display log events which are already collected in a generic list. There are thousands of them, I'd like to explore the limits. ListBox does not contain columns to show specific fields :(

              Чесноков

              1 Reply Last reply
              0
              • C Chesnokov Yuriy

                OriginalGriff wrote:

                How do you find what you want in a list of 100,000 items

                There is scroll bar, I can scroll them all easily :) and find event I'm looking for. Filtering is another extension to consider, the problem is to load them all at once. Why Microsoft can do that and we can't? Was it the serious desing flaw in windows event viewer or not we may further argue.

                OriginalGriff wrote:

                Does Google load all 10,000 hits into a single page

                Perhaps there might be other reasons we may ask google. I presume it may hang IE, firefox or any other browser and induce them to consume all the free mem. If it hangs IE to load some of the pages with java which fits into a single window, consider what would happen with a page consisted of 10000 links.

                Чесноков

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #17

                Chesnokov Yuriy wrote:

                There is scroll bar, I can scroll them all easily

                Try scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".

                Chesnokov Yuriy wrote:

                Why Microsoft can do that and we can't?

                You're referring to the Spy-program, where a ListBox is used for logging. Microsoft is using the same technique in it's Sql Profiler. The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry. Now, adding text to a collection that's displayed in a control doesn't take much time. Loading a lot of records from your database and adding them to your list will take a lot of time, especially if Windows keeps repainting after each fresh insert.

                Chesnokov Yuriy wrote:

                Perhaps there might be other reasons we may ask google. I presume it may hang IE, firefox or any other browser and induce them to consume all the free mem.

                That's far-fetched, your computer won't run out of memory if Google replies with more than 50 results. It would be rediculous to assume that you're going to read over 500 results, so they send you what you're probably going to use. How often did you navigate to the second result-page?

                I are Troll :suss:

                C 1 Reply Last reply
                0
                • C Chesnokov Yuriy

                  Dave Kreskowiak wrote:

                  You have a serious design flaw in your app if you think you need to show 100,000 items in a single control.

                  Have you ever ran Windows Events on your machine? How many events are there in a list view for a couple of years e.g. windows applications :) It does not freeze as you run it either.

                  Чесноков

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #18

                  Chesnokov Yuriy wrote:

                  Windows Events

                  Huh? If you're referring to Event Viewer, then yes, I have. And to counter, have you ever looked at ALL of those events, or just the last 100 or so?? Notice how long it takes to populate that list of 1,000 events?? I rest my case. I know it doesn't freeze. That's because it's adding all those events from a background thread, and not all at one time.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  C 1 Reply Last reply
                  0
                  • C Chesnokov Yuriy

                    It is possible to run addition of items in background worker but it needs to add them in report progress handler, main thread only, which also hangs the application. Is there any other approaches to add them to list view without application freeze?

                    Чесноков

                    P Offline
                    P Offline
                    Paw Jershauge
                    wrote on last edited by
                    #19

                    Thats Easy. just use the listview in virtual mode m8 ;) I have some listviews with over a million entries, and my app dont freeze at all. ;) Just remember to use cached items that also ups the preformance ;) Heres the guideline from MSDN http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.virtualmode.aspx[^] Happy codeing

                    With great code, comes great complexity, so keep it simple stupid...:-\ :-\

                    L C 2 Replies Last reply
                    0
                    • P Paw Jershauge

                      Thats Easy. just use the listview in virtual mode m8 ;) I have some listviews with over a million entries, and my app dont freeze at all. ;) Just remember to use cached items that also ups the preformance ;) Heres the guideline from MSDN http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.virtualmode.aspx[^] Happy codeing

                      With great code, comes great complexity, so keep it simple stupid...:-\ :-\

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #20

                      Which is exactly the answer I gave!

                      I must get a clever new signature for 2011.

                      P C 2 Replies Last reply
                      0
                      • L Lost User

                        Chesnokov Yuriy wrote:

                        There is scroll bar, I can scroll them all easily

                        Try scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".

                        Chesnokov Yuriy wrote:

                        Why Microsoft can do that and we can't?

                        You're referring to the Spy-program, where a ListBox is used for logging. Microsoft is using the same technique in it's Sql Profiler. The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry. Now, adding text to a collection that's displayed in a control doesn't take much time. Loading a lot of records from your database and adding them to your list will take a lot of time, especially if Windows keeps repainting after each fresh insert.

                        Chesnokov Yuriy wrote:

                        Perhaps there might be other reasons we may ask google. I presume it may hang IE, firefox or any other browser and induce them to consume all the free mem.

                        That's far-fetched, your computer won't run out of memory if Google replies with more than 50 results. It would be rediculous to assume that you're going to read over 500 results, so they send you what you're probably going to use. How often did you navigate to the second result-page?

                        I are Troll :suss:

                        C Offline
                        C Offline
                        Chesnokov Yuriy
                        wrote on last edited by
                        #21

                        Eddy Vluggen wrote:

                        ry scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".

                        :-D honestly, you have to scroll to specific time, and event icons are pretty distinct, and it is very easy to quickly locate minority of error lines with red icons among majority of bluish info events. while scrolling time column is pretty visible as you scroll it. I'm off alcohol :laugh: that enables me to scroll in less than second entire list

                        Eddy Vluggen wrote:

                        The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry.

                        I've just rechecked in Event Viewer events logs, scroll bar is so small that entire list is filled. You can scroll to any place. I do not know it might be some undocumented feature or they are using virtual view.

                        Eddy Vluggen wrote:

                        rediculous to assume that you're going to read over 500 results,

                        I do so always, rather than clicking 50 times to forward to next item, I prefer scroll bar move.

                        Чесноков

                        P L N 3 Replies Last reply
                        0
                        • C Chesnokov Yuriy

                          Eddy Vluggen wrote:

                          ry scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".

                          :-D honestly, you have to scroll to specific time, and event icons are pretty distinct, and it is very easy to quickly locate minority of error lines with red icons among majority of bluish info events. while scrolling time column is pretty visible as you scroll it. I'm off alcohol :laugh: that enables me to scroll in less than second entire list

                          Eddy Vluggen wrote:

                          The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry.

                          I've just rechecked in Event Viewer events logs, scroll bar is so small that entire list is filled. You can scroll to any place. I do not know it might be some undocumented feature or they are using virtual view.

                          Eddy Vluggen wrote:

                          rediculous to assume that you're going to read over 500 results,

                          I do so always, rather than clicking 50 times to forward to next item, I prefer scroll bar move.

                          Чесноков

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #22

                          Why not show your design to some users and see what they think of having to scroll through that many items? Get their feedback before you commit to it.

                          I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                          Forgive your enemies - it messes with their heads

                          My blog | My articles | MoXAML PowerToys | Onyx

                          1 Reply Last reply
                          0
                          • D Dave Kreskowiak

                            Chesnokov Yuriy wrote:

                            Windows Events

                            Huh? If you're referring to Event Viewer, then yes, I have. And to counter, have you ever looked at ALL of those events, or just the last 100 or so?? Notice how long it takes to populate that list of 1,000 events?? I rest my case. I know it doesn't freeze. That's because it's adding all those events from a background thread, and not all at one time.

                            A guide to posting questions on CodeProject[^]
                            Dave Kreskowiak

                            C Offline
                            C Offline
                            Chesnokov Yuriy
                            wrote on last edited by
                            #23

                            Dave Kreskowiak wrote:

                            That's because it's adding all those events from a background thread

                            Yes, Event Viewer, but scroll bar is height is pretty small. There is impression it is naturally populated. It might be in virtual view or manually driven.

                            Dave Kreskowiak wrote:

                            That's because it's adding all those events from a background thread

                            I do so also. Once you scroll to a middle it displays events in the middle. It'd be rather complicated to simulate the scroll and show only specific items from the middle.

                            Dave Kreskowiak wrote:

                            have you ever looked at ALL of those

                            I did once without problems in PC store when bought a laptop. I had to quickly browse them all to make sure computer was without glitches. I do not have any problems. It is easy just to scroll with a mouse to any particular day and then fine scroll with pgup, pgdwn further :)

                            Чесноков

                            1 Reply Last reply
                            0
                            • P Paw Jershauge

                              Thats Easy. just use the listview in virtual mode m8 ;) I have some listviews with over a million entries, and my app dont freeze at all. ;) Just remember to use cached items that also ups the preformance ;) Heres the guideline from MSDN http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.virtualmode.aspx[^] Happy codeing

                              With great code, comes great complexity, so keep it simple stupid...:-\ :-\

                              C Offline
                              C Offline
                              Chesnokov Yuriy
                              wrote on last edited by
                              #24

                              you've the right answer while others complaining they can not handle 1000 lines without a bottle of Jack's :laugh: http://www.codeproject.com/Messages/3753678/Re-How-to-load-100-000-list-view-items-without-app.aspx[^] millions of entries, I could not ever dream of that :) I hope virtual view is not so hard of coding...

                              Чесноков

                              P N 2 Replies Last reply
                              0
                              • C Chesnokov Yuriy

                                Eddy Vluggen wrote:

                                ry scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".

                                :-D honestly, you have to scroll to specific time, and event icons are pretty distinct, and it is very easy to quickly locate minority of error lines with red icons among majority of bluish info events. while scrolling time column is pretty visible as you scroll it. I'm off alcohol :laugh: that enables me to scroll in less than second entire list

                                Eddy Vluggen wrote:

                                The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry.

                                I've just rechecked in Event Viewer events logs, scroll bar is so small that entire list is filled. You can scroll to any place. I do not know it might be some undocumented feature or they are using virtual view.

                                Eddy Vluggen wrote:

                                rediculous to assume that you're going to read over 500 results,

                                I do so always, rather than clicking 50 times to forward to next item, I prefer scroll bar move.

                                Чесноков

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #25

                                Chesnokov Yuriy wrote:

                                and event icons are pretty distinct

                                Not if they scroll by at Mach 2.1 :laugh:

                                Chesnokov Yuriy wrote:

                                and it is very easy to quickly locate minority of error lines with red icons among majority of bluish info events

                                I have a checkbox for that - a single click and all you see are ListView items with a red cross :)

                                Chesnokov Yuriy wrote:

                                while scrolling time column is pretty visible as you scroll it. I'm off alcohol Laugh that enables me to scroll in less than second entire list

                                I don't mind scrolling through the event-log, or the log of the profiler, since I'm expecting a list. I wouldn't recommend the same pattern for database-records representing business-objects. But my apologies, you're right, there are circumstances where it might be appropriate :)

                                Chesnokov Yuriy wrote:

                                I've just rechecked in Event Viewer events logs, scroll bar is so small that entire list is filled. You can scroll to any place. I do not know it might be some undocumented feature or they are using virtual view.

                                It's probably not in .NET. Anyway, there should be a virtual-listview example somewhere on MSDN, give it a try.

                                Chesnokov Yuriy wrote:

                                I do so always, rather than clicking 50 times to forward to next item, I prefer scroll bar move.

                                I prefer hitting PgDwn, since it takes effort to move my hand from the keyboard and move it to the mouse. Having "pages" to browse through seems to work for a lot of people, especially if there's a nice index at the bottom. Other people prefer a autocomplete-textbox, or indeed, the scrollbar. Do the Microsoft-thing, and implement 'em all! :cool:

                                I are Troll :suss:

                                1 Reply Last reply
                                0
                                • C Chesnokov Yuriy

                                  Eddy Vluggen wrote:

                                  ry scrolling 100k items on my machine, locating the entry with the name "Bla400x". You could finish an entire bottle of Jacks' before you even reached the entries that start with a "B".

                                  :-D honestly, you have to scroll to specific time, and event icons are pretty distinct, and it is very easy to quickly locate minority of error lines with red icons among majority of bluish info events. while scrolling time column is pretty visible as you scroll it. I'm off alcohol :laugh: that enables me to scroll in less than second entire list

                                  Eddy Vluggen wrote:

                                  The difference is that it's merely adding a few items every second, and the user will rarely scroll through all the items to locate a particular entry.

                                  I've just rechecked in Event Viewer events logs, scroll bar is so small that entire list is filled. You can scroll to any place. I do not know it might be some undocumented feature or they are using virtual view.

                                  Eddy Vluggen wrote:

                                  rediculous to assume that you're going to read over 500 results,

                                  I do so always, rather than clicking 50 times to forward to next item, I prefer scroll bar move.

                                  Чесноков

                                  N Offline
                                  N Offline
                                  Not Active
                                  wrote on last edited by
                                  #26

                                  You have been given the same advice from several people now. Why are you continuing to argue the point? If you don't want to use the advice then don't ask for it.


                                  I know the language. I've read a book. - _Madmatt

                                  F 1 Reply Last reply
                                  0
                                  • C Chesnokov Yuriy

                                    you've the right answer while others complaining they can not handle 1000 lines without a bottle of Jack's :laugh: http://www.codeproject.com/Messages/3753678/Re-How-to-load-100-000-list-view-items-without-app.aspx[^] millions of entries, I could not ever dream of that :) I hope virtual view is not so hard of coding...

                                    Чесноков

                                    P Offline
                                    P Offline
                                    Paw Jershauge
                                    wrote on last edited by
                                    #27

                                    Virtual mode is very easy to use and code... just look at the guidline i gave you from microsoft, it shows you the way. But u need to know that virtual mode has its limits, with what it can do, compared to normal mode. ;)

                                    With great code, comes great complexity, so keep it simple stupid...:-\ :-\

                                    C 1 Reply Last reply
                                    0
                                    • L Lost User

                                      Which is exactly the answer I gave!

                                      I must get a clever new signature for 2011.

                                      P Offline
                                      P Offline
                                      Paw Jershauge
                                      wrote on last edited by
                                      #28

                                      Didnt see m8, sry ;)

                                      With great code, comes great complexity, so keep it simple stupid...:-\ :-\

                                      1 Reply Last reply
                                      0
                                      • C Chesnokov Yuriy

                                        you've the right answer while others complaining they can not handle 1000 lines without a bottle of Jack's :laugh: http://www.codeproject.com/Messages/3753678/Re-How-to-load-100-000-list-view-items-without-app.aspx[^] millions of entries, I could not ever dream of that :) I hope virtual view is not so hard of coding...

                                        Чесноков

                                        N Offline
                                        N Offline
                                        Not Active
                                        wrote on last edited by
                                        #29

                                        No you missed the point. No one was telling you they couldn't handle it, or that the controls could not support it. They have been telling you it is not a good design. And using the argument that Microsoft does it is not valid. The Event Viewer and such controls are written specifically for high performance situation in C++. You are not doing that are you?


                                        I know the language. I've read a book. - _Madmatt

                                        U 1 Reply Last reply
                                        0
                                        • N Not Active

                                          No you missed the point. No one was telling you they couldn't handle it, or that the controls could not support it. They have been telling you it is not a good design. And using the argument that Microsoft does it is not valid. The Event Viewer and such controls are written specifically for high performance situation in C++. You are not doing that are you?


                                          I know the language. I've read a book. - _Madmatt

                                          U Offline
                                          U Offline
                                          User 167261
                                          wrote on last edited by
                                          #30

                                          this entire thread got way too much attention...

                                          do or do not, there is no try

                                          C 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