Using variables as Objects Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I am trying to use a variable which retrieves an object name, such as

string objObject = databaseobject("Fieldname")

and using the objObject to refer to a object, such as a button, textbox
or form within the current form and changing stuffs like objObject.text =
"blahblahblah".

Is this possible? If so, how?

thanks.
 
Hey all,

Well.. i found the answer, it is as follows

this.Controls[(string)databaseobject("Fieldname")].Visible = false;
 
I advise you to put this statement between try...catch or to validate first
if your control exists (and does not return null) because you will have
exceptions fusing all over the place if it doesn't exist... ;)

You may also want to explore System.Runtime.Reflection to retrieve/invoke
your object's properties and methods at runtime.

I hope it helps

ThunderMusic

Rotciv said:
Hey all,

Well.. i found the answer, it is as follows

this.Controls[(string)databaseobject("Fieldname")].Visible =
false;

Rotciv said:
Hi all,

I am trying to use a variable which retrieves an object name, such as

string objObject = databaseobject("Fieldname")

and using the objObject to refer to a object, such as a button,
textbox
or form within the current form and changing stuffs like objObject.text =
"blahblahblah".

Is this possible? If so, how?

thanks.
 
Roticv,

Just keep im mind that controls my not have name. If they are created in the
designer they always do, but I doubt some one bother giveing names to
controls created by code.


--
Stoitcho Goutsev (100)

Rotciv said:
Hey all,

Well.. i found the answer, it is as follows

this.Controls[(string)databaseobject("Fieldname")].Visible =
false;

Rotciv said:
Hi all,

I am trying to use a variable which retrieves an object name, such as

string objObject = databaseobject("Fieldname")

and using the objObject to refer to a object, such as a button,
textbox
or form within the current form and changing stuffs like objObject.text =
"blahblahblah".

Is this possible? If so, how?

thanks.
 
Back
Top