Solved

For each in Me.Controls

Posted on 2006-07-17
8
239 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

16 Experts available now in Live!

Get 1:1 Help Now