hey
sorry for my lame entry, but I have such a problem:
I have like 30 textbox controls on form, and I want to refer to them by name, but I want to pass name as parameter
I tried some stupid things but no result, any ideas?
thanks in advance
hey
sorry for my lame entry, but I have such a problem:
I have like 30 textbox controls on form, and I want to refer to them by name, but I want to pass name as parameter
I tried some stupid things but no result, any ideas?
thanks in advance
Could you perhaps be more specific. What are you trying to accomplish?
I want to automate working with controls,
the general idea is that I will construct string, that will be used as reference to control name, for example I have string myIndex = "textBoxA1" and I want use it in such pseudo-code like I found below
// C# pseudo-code
myControl[myIndex].MyProperty = myValue;
myControl[myIndex + 1].MyMethod
exactly:
textBox[myIndex].Enable = true;
or
textBox[2].Enable = true;
I tried with this code either with numbers or with string-name, no juice
All controls have a Controls collection that can be indexed using the name of the child control as a string.
A form is just another type of control and also has the Controls property.
e.g. MyForm.Controls["textBoxA1"].Enable = true;
However, to access your own properties and methods for custom controls you must cast to your control type first.
e.g. ((MyControl)MyForm.Controls["MyControl1"]).MyProperty = NewValue;
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.