D
Dan Tallent
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.GetType();
if (oType == typeof(System.Windows.Forms.TextBox))
{
((System.Windows.Forms.TextBox)oControl).ReadOnly == 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.TextBox));
DevControls.Add(typeof(System.Windows.Forms.ComboBox));
Type oType = oControl.GetType();
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).ReadOnly = true;
}
}
//==============================================
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.GetType();
if (oType == typeof(System.Windows.Forms.TextBox))
{
((System.Windows.Forms.TextBox)oControl).ReadOnly == 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.TextBox));
DevControls.Add(typeof(System.Windows.Forms.ComboBox));
Type oType = oControl.GetType();
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).ReadOnly = true;
}
}
//==============================================