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
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?
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?
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).
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?
Re: Accessing objects using their name reference through string variables
Ah, they are all fixed controls....
Re: Accessing objects using their name reference through string variables
I wonder, do you have a background in web programming?
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!
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!
Re: Accessing objects using their name reference through string variables
Tks for your time and for chatting.... I got it and already done!