Solved

Clearing Tree and Listviews

Posted on 2000-02-23
6
182 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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