-
May 2nd, 2013, 11:36 AM
#1
Accessing objects using their name reference through string variables
I have an check box name into a string variable as follows : String Myvar = "checkbox01".
I want to access the check box properties doing something like Myvar.checked = true; as I was referring direct to the string content or maybe Mayvar.text = "New-text"...
Is there a way to make C# understand this?
Thank you very much.
Gus
-
May 2nd, 2013, 01:24 PM
#2
Re: Accessing objects using their name reference through string variables
Um, this usually leads to some hard to maintain code. What's the bigger picture on what you are trying to accomplish?
-
May 2nd, 2013, 01:38 PM
#3
Re: Accessing objects using their name reference through string variables
Actualy I am trying exactely the opposite, to get a ease to mantain code. I used the name of the components in my form to know the namo of the refered other components, as so, just for an example, I have a check box named "check_01_hora_1011" and also I have a radio button named "prim_dia_radio", when both are selected, a textbox named "banda_prim_1011" must be visible and enable to be fullfiled, and, if you noticed, I can have the name of the right textbox just combinig peaces of the other two controls, I take the "1011" substring from the check box name and the "prim" substring from the radio name and then I can get the "banda_PRIM_1011" textbox name... The trik I have to do than is how to make "banda_prim_1011".text ou other property to run properly. Do you got it?
-
May 2nd, 2013, 01:52 PM
#4
Re: Accessing objects using their name reference through string variables
Oh I got it. I just happen to think it's a bad idea.
If these are static controls (i.e. fixed controls on a form), you are going to have some dev in the future not understand the naming convention and screw things up.
If the controls aren't static and you are building them dynamically, then there isn't any need to use a string to access the control (because you have the reference to the control already).
-
May 2nd, 2013, 01:57 PM
#5
Re: Accessing objects using their name reference through string variables
I am the only developer envolved and will always be, because I am writing this code for my personal use only in a specific personal project. Anyway, Do you know how to solve this?
-
May 2nd, 2013, 01:57 PM
#6
Re: Accessing objects using their name reference through string variables
Ah, they are all fixed controls....
-
May 2nd, 2013, 02:14 PM
#7
Re: Accessing objects using their name reference through string variables
I wonder, do you have a background in web programming?
-
May 2nd, 2013, 02:17 PM
#8
Re: Accessing objects using their name reference through string variables
not much, but I am a hard researcher and a hard student... If you have any ideas that may lead to a solution "I am all ears".... shoot it!
-
May 2nd, 2013, 02:35 PM
#9
Re: Accessing objects using their name reference through string variables
not much, but I am a hard researcher and a hard student... If you have any ideas that may lead to a solution "I am all ears".... shoot it!
-
May 2nd, 2013, 02:36 PM
#10
Re: Accessing objects using their name reference through string variables
Tks for your time and for chatting.... I got it and already done!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|