Solved

For each in Me.Controls

Posted on 2006-07-17
8
242 Views
Last Modified: 2011-09-20
Hi,

I got many buttons okay. Lets say 6 with their names:   Button1, Button2, Button3 etc.
I want to manipulate for example Button4.

I would like to manipulate that way:

dim str = "Button", x as Integer = 1
("Button" + x).Name .....

I know, we cant do that. I know its possible by the way of a For each than you check the ctrl.Name , then if its then same, you can play with it. But I tought it was not 100% efficiant.  Is there a way like my ("Button" + x)  to call that button other than a for each, other than calling Button4.name too ... the thing is, it will be never the same button. It might change that why I was needed that integer (x) or a for each

Thanks
0
Comment
Question by:PhilippeRenaud
  • 3
  • 3
8 Comments
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 150 total points
ID: 17122818
Hi PhilippeRenaud;

Place the controls in a Hash Table with the key as the controls name and then you can get the control using its name.

Fernando
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17122823
What version of .Net are you using 2003 or 2005?
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17122834
2005
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Accepted Solution

by:
Jeff Certain earned 350 total points
ID: 17122855
Then use Dictionary(of string, button) and put the buttons in the dictionary using the control name as the key...

Imports system.Collections.Generic
Dim controls as Dictionary(Of string, button)

private function GetButton(buttonName as string) as button
If controls.ContainsKey(buttonName) then
  return controls(buttonName)
else
  return nothing
End If

End Function
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17122882
In 2005 you can do this

     Dim btn() As Control = Me.Controls.Find("Button5", True)

Fernando
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17122895
I wanted to split points, But i clicked at the wrong place
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 17122999
Well, the hastable do the same thing i guess, but I found it great to do it with a dictionnary.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now