Need to Set Readonly Property to ChildControls
-
Hi All, How to set the all child control in Panel to Readonly Mode. i have nearly 18 TB, 10 RadioButtionList and 10 DropdownLists in Panel Control. Need a function which set the all the controls Readonly mode..
JohnDas
You can loop through the control collection for the panel and set the ReadOnly property as true wherever applciable. You can make use of reflection instead of switch cases. Like this:
PropertyInfo propInfo = this.Controls[ctrlIndex].GetType().GetProperty("ReadOnly");
if(propInfo != null)
propInfo.SetValue(this.Controls[ctrlIndex], true, null);In case the control does not has a ReadOnly property, you can check for
Enabled
.50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
You can loop through the control collection for the panel and set the ReadOnly property as true wherever applciable. You can make use of reflection instead of switch cases. Like this:
PropertyInfo propInfo = this.Controls[ctrlIndex].GetType().GetProperty("ReadOnly");
if(propInfo != null)
propInfo.SetValue(this.Controls[ctrlIndex], true, null);In case the control does not has a ReadOnly property, you can check for
Enabled
.50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
Good answer.... :rose:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
Good answer.... :rose:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
You can loop through the control collection for the panel and set the ReadOnly property as true wherever applciable. You can make use of reflection instead of switch cases. Like this:
PropertyInfo propInfo = this.Controls[ctrlIndex].GetType().GetProperty("ReadOnly");
if(propInfo != null)
propInfo.SetValue(this.Controls[ctrlIndex], true, null);In case the control does not has a ReadOnly property, you can check for
Enabled
.50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
Good answer! I was think about using switch case with in a loop, but this is even simpler! Very good & Thanks!:rose: