stringA = "btn"
stringB = "Mine"
stringC = stringA & stringB
'now need a way to set btnMine property, like:
(stringC).text = "Click Me" 'like btnMind.text = "Click Me"
...of course, that doesn't work. Is there anything that does?
Thanks,
-Kathleen Christian
"Kathleen" <not_...@hotmail.com> schrieb:
> Is there any way I can get the id of a control in a string,
> and then use it to set properties of that control.
\\\
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Load
Dim i As Integer
Dim obj As Object
For i = 1 To 40
DirectCast( _
SearchControl( _
Me, _
"pyramide" & i.ToString() _:
), _
Button _
).BackColor = Color.Red
Next i
End Sub
Private Function FindControl( _
ByRef Container As Control, _
ByVal Name As String _
) As Control
Return SearchControl(Container, Name)
End Function
Private Function SearchControl( _
ByRef Control_ As Control, _
ByRef Name_ As String _
) As Control
If Control_.Name = Name_ Then
Return Control_
End If
Dim ctr As Control
Dim c As Control
For Each ctr In Control_.Controls
c = SearchControl(ctr, Name_)
If Not c Is Nothing Then
Return c
End If
Next ctr
End Function
///
Regards,
Herfried K. Wagner
Variable names, like btnMind, shouldn't matter at run time (I've never
needed it so far). What's your intention? Why not use btnMine.text = "Click
Me" ?
--
Armin
Thanks!!!
-Kathleen
"Herfried K. Wagner" <hirf...@m.activevb.de> wrote in message
news:em6Im#T$CHA....@TK2MSFTNGP12.phx.gbl...
I was considering the kind of code you gave here but wondered if there were
not a more direct approach; in JScript, you can do this sort of thing with
Eval(StringA + StringB).Text = "Some new string"
Does VB.NET not have some equivalent ?
"Liz" <lizs...@swbell.net> schrieb:
> I was considering the kind of code you gave here
> but wondered if there were not a more direct approach;
> in JScript, you can do this sort of thing with
>
> Eval(StringA + StringB).Text = "Some new string"
>
> Does VB.NET not have some equivalent ?
IMHO there is no "one-command" equivalent. Eval statements are usually contained
in scripting languages.
Regards,
Herfried K. Wagner
Prefer calling this routine from the page_load routine if IsPostBack, so I
don't have to put an OnServerValidate clause in each control.
-Kathleen
"Armin Zingler" <dontwa...@anywhere.de> wrote in message
news:#57VfCU$CHA....@TK2MSFTNGP11.phx.gbl...
Sorry, don't know ASP. In Winforms, I'd add the controls to an array or
iterate the controls collection (for each).
Armin
> Trying to check on a bunch of controls, and change each one's color if
> they're checked. Want to do it with one routine rather than writing the
> same code over and over again.
>
> Prefer calling this routine from the page_load routine if IsPostBack, so
> I
> don't have to put an OnServerValidate clause in each control.
>
> -Kathleen
>
As I said in a previous message, you can do CType(FindControl("chkBox"),
CheckBox).ForeColor = ...
but it might be easier if you did something like:
For Each ctl in Controls
If TypeOf(ctl) Is CheckBox Then
ctl.ForeColor = ...
End If
Next
If you have other checkboxes on the page that you don't want to change the
color of, you can put all the ones you do on a panel, and then just iterate
through the controls on that panel, rather than the page.
For Each ctl in pnl.Controls
...
Next
Forgive me if the syntax isn't 100% correct. I'm on a machine without
VS.NET on it, and I'm trying to do this from memory. It should get you
pretty close, though.