Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > TreeView Control Arrays
 

TreeView Control Arrays

Hi,

In VB6 I wrote a form that had a control array of treeview controls.

When upgraded to .NET - which does not support control arrays - it now does not work as there is no control array object in Microsoft.VisualBasic.Compatibility.VB6 namespace like there is for some of the other controls e.g. TextBoxArray

Does anyone know of a way to emulate VB6 stylecontrol arrays for Tree View controls ?

Regards

Michael Green

ASGMikeG  Sunday, March 05, 2006 10:08 PM

Hi Michael,

As far as I'm aware, you can't completely emulate control arrays. I might be wrong, but I taught myself very early in my .net learning to just avoid them :)

If you really need an array of them, you could always insert them into an array yourself - but it depends on what you want to do with them.

For example, you might drop 3 treeviews on your form (lets call them Treeview1, 2 and 3). You could then put this at the top of your form code:

PrivateTreeViewArray(2) as Treeview

And then in, say, your FormLoad event you could do:

TreeViewArray(0) = Treeview1

TreeViewArray(1) = Treeview2

TreeViewArray(2) = Treeview3

But as I said, why do you need it? Are you just trying to reduce the amount of upgrade code you need to write, or are you trying to do something in particular?

--Geoff

geoff.appleby  Monday, March 06, 2006 5:48 AM

Geoff,

Yes - I am trying to avoid having to re-write lots of upgraded code - or at least simplify the exericse.

I have 8 treeview controls that were in a control array - basically do exactly the same thing on different sub-sets of data.

I need to be able to access them as an array and handle events in the same module.

Best I've been able to come up with so far is :

- A custom class that handles an collection of treeview controls

- modifying event handles so that the one event - which used to work with VB6 control arrays - now instead handles events for multiple hard coded control names i.e. the 8 treeview controls

However this doesn't help me if I need to dynamically add treeview controls......

Regards

Michael

ASGMikeG  Tuesday, March 07, 2006 12:23 AM

In VB.NET although you don't havce control arrays you can hookup multiple controls to the same piece of code.

As the code name of the procedure is rather irrelevent now as it was in VB6. So example you create a button click even by double clicking the button and put some code in here - lets say a piece of validation code.

You can then add other control events onto the procedure and chnage the name to something more relevent. This is simple as adding on additional events to the handles clause.

The benefit here is that the events don't all need to be click events and they don't even have to be of the same control type - so you can hookup the code to numerous events from numerous controls.

If you want to create an effect of a control array you can cycle through the form controls and then search for a common name example CmdButton for the command name and all the buttons such as CmdButton1, CmdButton2, CmdButton3 will be processed but its not exactley efficient and just hooking up the events from you 8 treeviews may be a better approach.

spotty  Tuesday, March 07, 2006 3:04 AM

You can use google to search for other answers

Custom Search

More Threads

• write to BIN file prob
• Addhandler with a user controls event
• File Watcher
• "ENTER" key pressed in textbox?
• optimize my APP
• Can I use one ScrollBar to set the values of 2 other ScrollBars?
• vb duplicate form
• Need to override 'Disabled' font for Windows Forms control
• ArrayTypeMismatchException with generic arrays
• Puzzling behaviour of If operator