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. Visual Basic
  4. TreeView redraw lag..

TreeView redraw lag..

Scheduled Pinned Locked Moved Visual Basic
c++data-structuresquestion
5 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
    dazinith
    wrote on last edited by
    #1

    my treeview is very very laggy when calling TreeView.Nodes.Clear.. ive found that if i call TreeView.Invisible = TRUE before clearing the tree, then make it visible again afterwards that it is much much faster.. in C++ i use a comand SetRedraw(FALSE) before clearing the list, then SetRedraw(TRUE) afterwards.. is there anything like this for VB, or is making the list invisible the only hack? populating the list is just as slow as well unless i make it invisible first.. anyway to turn off the redraw without making it invisible? thanks! still a newb.. cut me some slack :P -dz

    M 3 Replies Last reply
    0
    • D dazinith

      my treeview is very very laggy when calling TreeView.Nodes.Clear.. ive found that if i call TreeView.Invisible = TRUE before clearing the tree, then make it visible again afterwards that it is much much faster.. in C++ i use a comand SetRedraw(FALSE) before clearing the list, then SetRedraw(TRUE) afterwards.. is there anything like this for VB, or is making the list invisible the only hack? populating the list is just as slow as well unless i make it invisible first.. anyway to turn off the redraw without making it invisible? thanks! still a newb.. cut me some slack :P -dz

      M Offline
      M Offline
      mikasa
      wrote on last edited by
      #2

      Yes, this is super easy: TreeView.BeginUpdate() TreeView.Nodes.Clear TreeView.EndUpdate()

      1 Reply Last reply
      0
      • D dazinith

        my treeview is very very laggy when calling TreeView.Nodes.Clear.. ive found that if i call TreeView.Invisible = TRUE before clearing the tree, then make it visible again afterwards that it is much much faster.. in C++ i use a comand SetRedraw(FALSE) before clearing the list, then SetRedraw(TRUE) afterwards.. is there anything like this for VB, or is making the list invisible the only hack? populating the list is just as slow as well unless i make it invisible first.. anyway to turn off the redraw without making it invisible? thanks! still a newb.. cut me some slack :P -dz

        M Offline
        M Offline
        mikasa
        wrote on last edited by
        #3

        Doh! Sorry, using .NET here... Anyway, use the API Function "LockWindowUpdate". Public Declare Function LockWindowUpdate Lib "user32" (ByVal hWndLock As Long) As Long Then, use this function when Populating or Clearing the TreeView. Call LockWindowUpdate(Tree.hWnd) 'Populate or Clear Nodes Call LockWindowUpdate(0) Always remember to "UnLock" after you are done, otherwise it never repaints. Also, if you are updating more controls (i.e. ComboBoxes) that are on the same Form, just Lock the Whole Form that way painting will not occur on any controls. I use this in my App all the time and it has sped up the process of loading Forms by up to 70%!

        D 1 Reply Last reply
        0
        • M mikasa

          Doh! Sorry, using .NET here... Anyway, use the API Function "LockWindowUpdate". Public Declare Function LockWindowUpdate Lib "user32" (ByVal hWndLock As Long) As Long Then, use this function when Populating or Clearing the TreeView. Call LockWindowUpdate(Tree.hWnd) 'Populate or Clear Nodes Call LockWindowUpdate(0) Always remember to "UnLock" after you are done, otherwise it never repaints. Also, if you are updating more controls (i.e. ComboBoxes) that are on the same Form, just Lock the Whole Form that way painting will not occur on any controls. I use this in my App all the time and it has sped up the process of loading Forms by up to 70%!

          D Offline
          D Offline
          dazinith
          wrote on last edited by
          #4

          thanks a ton for the suggestions, works well! thanks again! still a newb.. cut me some slack :P -dz

          1 Reply Last reply
          0
          • D dazinith

            my treeview is very very laggy when calling TreeView.Nodes.Clear.. ive found that if i call TreeView.Invisible = TRUE before clearing the tree, then make it visible again afterwards that it is much much faster.. in C++ i use a comand SetRedraw(FALSE) before clearing the list, then SetRedraw(TRUE) afterwards.. is there anything like this for VB, or is making the list invisible the only hack? populating the list is just as slow as well unless i make it invisible first.. anyway to turn off the redraw without making it invisible? thanks! still a newb.. cut me some slack :P -dz

            M Offline
            M Offline
            mikasa
            wrote on last edited by
            #5

            Actually, I figured I would Post this here. This function will Lock as many Windows as you want from Redrawing...unlike the "LockWindowUpdate" Function.

            'API Declarations (.NET)
            Private Declare Ansi Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
            'Routine to Lock a Window from Repainting
            Public Sub LockWindowUpdate(ByVal Handle As IntPtr, ByVal Lock As Boolean)
            Const WM_SETREDRAW As Integer = &HB

            'Enable / Disable Drawing
            Call SendMessage(Handle, WM\_SETREDRAW, Math.Abs(CInt(Lock)), 0)
            

            End Sub

            'API Declarations (VB6)
            Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
            'Routine to Lock a Window from Repainting
            Public Sub LockWindowUpdate(ByVal Handle As Long, ByVal Lock As Boolean)
            Const WM_SETREDRAW As Long = &HB

            'Enable / Disable Drawing
            Call SendMessage(Handle, WM\_SETREDRAW, Abs(CInt(Lock)), 0)
            

            End Sub

            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