vb.net; controls

J

jax1148

In vb6 a group of controls ie command buttons could be refered to by
an index number ie cmdWord(4). This was accomplished by using the
index property of the control. Vb.net does not seem to have the index
property for buttons. Is there a way in vb.net to refer to a group of
controls in a way that includes a unique index number for the
specific control to be used?

Thanks,
Howard Haisten
 
C

Chris

In vb6 a group of controls ie command buttons could be refered to by
an index number ie cmdWord(4). This was accomplished by using the
index property of the control. Vb.net does not seem to have the index
property for buttons. Is there a way in vb.net to refer to a group of
controls in a way that includes a unique index number for the
specific control to be used?

Thanks,
Howard Haisten

You could add all the button controls to an array on form load.

For Each C as Control in Me.Controls
if typeof C is Button then
'Add to Array
end if
End if
 
T

Theo Verweij

This way, you do not know which button has what index in the array.
If you need to know this, you have to do it by hand, ie:

Dim x(1) as button

x(0)=button1
x(2)=button2

then you can use x in the same way as the controlarray in vb6
 
T

Tim Patrick

If you convert a VB6 project that contains control arrays to VB.NET using
the upgrade wizard, it will add code that simulates control arrays using
some VB6-backward-compatibility classes. Look at that code to see how Microsoft
does it. You can also just include the index number in the control name,
and then access controls as Me.Controls("lblInformation" & indexNumber).
 
T

Theo Verweij

Using Me.Controls("lblInformation" & IndexNumer) can cause a problem
when using obfuscating techniques.
 
C

Cor Ligthert [MVP]

Or a little bit more simple

Dim x() as button = {button1, button2}

Just a little addition the solution is correct in my opinion,

Cor
 
T

Tim Patrick

That's true. Personally, I have stopped using control array-type code in
my VB.NET applications, choosing to give unique names to each control. I
can bulk up your code a bit, although it is easy to use a common event handler
for all of the related controls. For those situations where it might make
sense to have a lot of controls with related logic, I try to find other means.
For instance, I implemented a simple numeric keypad. My processing needs
were met by using a common Click event, and using the Text (or Tag) property
of the control to complete my processing.

In other cases, I have migrated the independent controls to an owner-draw
list box or grid control, which turned out better anyway.
 
H

Herfried K. Wagner [MVP]

In vb6 a group of controls ie command buttons could be refered to by
an index number ie cmdWord(4). This was accomplished by using the
index property of the control. Vb.net does not seem to have the index
property for buttons. Is there a way in vb.net to refer to a group of
controls in a way that includes a unique index number for the
specific control to be used?

Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>
 
J

jax1148

On Fri, 27 Oct 2006 11:57:49 -0400, (e-mail address removed) wrote:

Thank you for your responses. I appreciate your help very much.
Perhaps as I gain more and more knowledge and skill will vb.net I'll
be able to be of assistance to someone else one day. I went with the
suggestion from Cor Lightert. It worked very well !!

Thanks again
Howard Haisten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top