No .: Qa004593 Date: March 23, 2002 Last modified: March 23, 2002 Category: Category:
Visual Basic - Windows 9X control
article:
Lee Hai translated from IVBTIPS. Although TreeView provides a Clear method to clear all nodes, the node is deleted one by one, which will be faster. You can use the following code: private sub trvwclear () DIM x as integer with treeview1.nodes for x = .count to 1 step -1 .remove x Next x end
With a simple API function, you will further improve performance. Unfortunately, when VB loops deletes TreeView nodes, it continually resembles controls to display the remaining nodes. This behavior will significantly reduce the speed of the process. The method we have to use is to prohibit TreeView from reanking its node when the node is deleted. Fortunately, the Windows API provides a function to do this. The SendMessage () function supports the WM_SETREDRAW message. With this message, your code can decide if a window should be resembled. Transfer TRUE (1) Allow the window to re-draw, or false (0) to block the drawing. Plus API code, we remove the code like this: Private Const WM_SETREDRAW = & HB Private Declare Function SendMessage Lib "user32" Alias _ "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _ Long, ByVal wParam As Long, lParam As Any) As long
Private Sub TrvwClear () Dim x As Integer With TreeView1 SendMessage .hwnd, WM_SETREDRAW, 0, 0 For x = .Nodes.Count To 1 Step -1 .Nodes.Remove x Next x SendMessage .hwnd, WM_SETREDRAW, 1, 0 End With End Sub
Adversely deleted the API is the fastest clearance of the TreeView control.
Article Source: Ivbtips.