Results 1 to 5 of 5

Thread: How to stop a listview from being painted.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95

    How to stop a listview from being painted.

    In my application I have a method that iterates over rows in a table to add them to a listview. When the listview is visible, the first few entries that go down till the edge of the application's window are really slow. As soon as it starts processing the entries that are out of view, it's fast.

    In my loop, which looks like this:

    VB Code:
    1. For Each row In rows
    2.  
    3.             Dim lvi As GlacialComponents.Controls.GLItem
    4.             lvi = glist.Items.Add(CType(row(1), String))
    5.  
    6.             lvi.SubItems(1).Text = (CType(row(2), String))
    7.             lvi.SubItems(1).ForeColor = Color.Maroon
    8.  
    9.             lvi.SubItems(2).Text = (CType(row(3), String))
    10.             lvi.SubItems(2).ForeColor = Color.DarkBlue
    11.  
    12.             lvi.SubItems(3).Text = (CType(row(5), String))
    13.  
    14.             lvi.SubItems(4).Text = (CType(row(6), String))
    15.             lvi.SubItems(4).ForeColor = Color.Green
    16.             lvi.SubItems(4).Font = verdanab
    17.  
    18.             lvi.SubItems(5).Text = (CType(row(7), String))
    19.             lvi.SubItems(5).ForeColor = Color.DarkBlue
    20.             lvi.SubItems(5).Font = verdanab
    21.  
    22.             lvi.SubItems(6).Text = (CType(row(4), String))
    23.  
    24.             lvi.SubItems(7).Text = (CType(row(12), String))
    25.  
    26.             progress.Value += 1
    27.  
    28.         Next row

    How can I stop the listview from painting on each row that way it processes quick? Then I can do glist.update() or is it glist.refresh() after the line with next row, is that right? Or am I missing something?

    I should mention that turning off visibility also does the trick, but I want the listview to show an empty "dummy list" for aesthetics purposes.

    This is essentially one of the last elements of my software before I go through and do some serious testing.

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    .BeginUpdate();

    your code....

    .EndUpdate();

    these 2 methods were put in place because in vb6 the only way to prevent repaint was to make it invisible,
    with .NET its easier, just use those 2 methods.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95
    Ok that definitely works but the screen flickers black. Is there any easy way to fix that? I guess I just wanna "freeze" the way the control looks before I start updating and then quickly repaint it afterwards.
    Last edited by Kt3; Apr 26th, 2004 at 12:58 PM.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    call the update method after your next statement. that lets the listview fill up and then it will be shown. Rather that be shown after every row which will cause it to flicker.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95
    That's what I assumed. I wouldn't want to update every time it loops, but either way, the screen still shows black for a few moments while it processes. No flickering, but still not pretty.

    I'm gonna leave it like that for now, but how about using the addrange method of the listview.items property? I tried creating a new itemcollection like this:

    VB Code:
    1. Dim collect As New GlacialComponents.Controls.GLItemCollection(glist)

    And during the loop, here's what happens:

    VB Code:
    1. Dim lvi As GlacialComponents.Controls.GLItem
    2.             lvi = collect.Add(CType(row(1), String))
    3.            ' ...
    4.            '<rest of code ommitted>

    but then I can't figure out how to add the Itemcollection to the listview after the next statement. The addrange method that belongs to the items property is supposed to do that but it accepts an "item array" and not an item collection, well what the hell is the difference?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width