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. ListView BeginUpdate not working

ListView BeginUpdate not working

Scheduled Pinned Locked Moved C#
helpcomjsonquestionannouncement
2 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.
  • D Offline
    D Offline
    Darryl Borden
    wrote on last edited by
    #1

    I have run into a problem when updating a ListView object with hundreds or thousands of records at a time. I do a listView1.BeginUpdate before I start and an EndUpdate when I am done, but even though the contents of the listview are not updating, it still takes an inordinate amount of time to update the object (15 seconds for 2000 items). If the listview is not visible (i.e. the tab the object is on in a tab control is not the selected tab), then it updates in a 10th of the time. I know there is a LockWindowUpdate available as an API call but either I am calling it wrong or it has no effect on the listview object. Can anyone out there help me out? Darryl Borden Principal IT Analyst darryl.borden@elpaso.com

    H 1 Reply Last reply
    0
    • D Darryl Borden

      I have run into a problem when updating a ListView object with hundreds or thousands of records at a time. I do a listView1.BeginUpdate before I start and an EndUpdate when I am done, but even though the contents of the listview are not updating, it still takes an inordinate amount of time to update the object (15 seconds for 2000 items). If the listview is not visible (i.e. the tab the object is on in a tab control is not the selected tab), then it updates in a 10th of the time. I know there is a LockWindowUpdate available as an API call but either I am calling it wrong or it has no effect on the listview object. Can anyone out there help me out? Darryl Borden Principal IT Analyst darryl.borden@elpaso.com

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      This is happening because, while the control is not visible, the Windows handle is not created. When the Windows handle is not created, no sorting (and a few other things) is done. If the control is visible - even if it isn't currently painting items - it sorts with each addition to the Items collection! Even using the LockWindowsUpdate API won't do anything to resolve this issue. The BeginUpdate and EndUpdate methods essentially do the same thing. They disable and enable drawing (respectively) by using the WM_SETREDRAW message. While it isn't documented, LockWindowsUpdate probably does this very same thing. So, you'll either have to bite the bullet and accept the lag, or hide your control and reshow it when you're finished, but that might be annoying to the user. If nothing else, show a progress bar (so add the items in a separate thread, but be sure to use InvokeRequired and Invoke to actually add the items!) while you're adding items to the user knows that something's happening and that they should way. You should also use a try-finally block to show the wait cursor (Cursor.Current = Cursors.WaitCursor) and, in the finally block, set it back to the default (Cursor.Current = Cursors.Default).

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      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