Solved

Clearing Tree and Listviews

Posted on 2000-02-23
6
181 Views
Last Modified: 2010-05-02
Does anyone know of a FAST way to clear Tree and Listview nodes and list items?

If your tree or List contains a small number of items, it's a simple matter to delete each node, but when the count is high, it takes as long to clear the views as it does to load them.

Since this behavior is true even in Windows explorer (try clicking on a subdirectory with thousands of items), there may not be a workable solution.

The "clear" command is not acceptable, as in a list view it still takes forever to remove the list items. And with a tree, the clear command clears all nodes, not just the selected node.

Thanks.
0
Comment
Question by:carpbyte
6 Comments
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 200 total points
ID: 2551276
Try setting it up as an Array of TreeView.. and Unloading the Control
then ReLoading it.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2551311
I do not think you can get it much faster than it is, using the M$ controls. If the speed is really important you can do like me, create your own usercontrol and using API's like DrawText, DrawIcon, DrawRectangle etc to emulate a listview control. Connect this to a database (not the M$ ones but your own database with simple textfiles or something) and you can too archieve the Clear method as long as it takes to do delete a file from your harddrive. But perhaps there is a way to create database-bound treeview/listviews with the standard M$ controls??
0
 
LVL 15

Expert Comment

by:ameba
ID: 2552616
Tell me if 2.5 x faster than Listitems.Clear is OK?
Also, are you sorting listitems?
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:carpbyte
ID: 2552992
I need a little more info for the ListView end of things.

For example the following code loads 10,000 items in a listview.

For x=1 to 1000
  Listview1.listitems.add ,,"List" & x
Next x

ListItems.clear takes awhile to clear it.

The same problem would occur if you clicked on another tree node as the listview has to clear all the previous items.


With the treeview you can just delete the topmost node and that takes care of things in the tree, but the listview doesn't have an equivalent heirachy (unless one can be created).

I don't quite follow how to set up an array of the control and removing it.  I get a "Can't unload this object" error.

Sample code would be appreciated.

Thanks.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2554835
You can not unload a control you have created in design-time. You can however create a control in run-time, set its Index property to 0 (zero) and use code like "Load controlname(1)" to instantiate a new control, use that control, and then use "Unload controlname(1)" to unload that new control.
0
 

Author Comment

by:carpbyte
ID: 2556367
AnswerMan's solution works thanks to the additional explanation from VBMaster regarding loading & unloading!

Thanks.

Carpbyte
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
add text to end of existing text in file 16 70
vb6 connector to SQL Server 2 37
Add and format columns in vb6 7 56
Formula problem with Excel attachment 6 26
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question