0

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

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by nick.crane
0

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

0

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;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.