I have code here that checks the type of an object and then cast it so I can
access its properties. In the simple example below I am accessing the
ReadOnly property that is unique to textbox controls. This code works
however I wanted to find out if its possible to write code using a
collection or array.. see below
Type oType = oControl.GetTyp e();
if (oType == typeof(System.W indows.Forms.Te xtBox))
{
((System.Window s.Forms.TextBox )oControl).Read Only == true;
}
//=============== =============== =============== =
So the code below is kinda what I have in mind. Notice the line where I
am attempting to cast. I know this code
doesn't work, but I am wondering if there is a way to code such a routine.
//=============== =============== =============== =
private ArrayList DevControls;
DevControls = new ArrayList();
DevControls.Add (typeof(System. Windows.Forms.T extBox));
DevControls.Add (typeof(System. Windows.Forms.C omboBox));
Type oType = oControl.GetTyp e();
for (int cnt = 0; cnt<DevControls .Count; cnt++)
{
if (DevControls[cnt] == oType)
{
// This line below is the question... is there a way to code
this ?
( (DevControls[cnt]) oControl).ReadO nly = true;
}
}
//=============== =============== =============== =
--
Thanks,
Dan
access its properties. In the simple example below I am accessing the
ReadOnly property that is unique to textbox controls. This code works
however I wanted to find out if its possible to write code using a
collection or array.. see below
Type oType = oControl.GetTyp e();
if (oType == typeof(System.W indows.Forms.Te xtBox))
{
((System.Window s.Forms.TextBox )oControl).Read Only == true;
}
//=============== =============== =============== =
So the code below is kinda what I have in mind. Notice the line where I
am attempting to cast. I know this code
doesn't work, but I am wondering if there is a way to code such a routine.
//=============== =============== =============== =
private ArrayList DevControls;
DevControls = new ArrayList();
DevControls.Add (typeof(System. Windows.Forms.T extBox));
DevControls.Add (typeof(System. Windows.Forms.C omboBox));
Type oType = oControl.GetTyp e();
for (int cnt = 0; cnt<DevControls .Count; cnt++)
{
if (DevControls[cnt] == oType)
{
// This line below is the question... is there a way to code
this ?
( (DevControls[cnt]) oControl).ReadO nly = true;
}
}
//=============== =============== =============== =
--
Thanks,
Dan
Comment