[C#] retrouver le type herite d'un contrôle
:salut:
Je cherches à passer tous mes controles textbox et dropdownlist en readonly (+ 150) via une méthodes.
Ceci marches au poil
Code:
1 2 3 4 5 6 7 8
|
foreach(Control c in this.Controls)
{
if (c is TextBox)
((TextBox)c).ReadOnly = true;
if (c is DropDownList)
((DropDownList)c).Enabled = false;
} |
Mais j'utilises des controles herités de textbox et dropdownlist pour la plupart.
Donc comment retrouver facilement le type de contrôle pour eviter d'avoir ca :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
foreach(Control c in this.Controls)
{
if (c is TextBox)
((TextBox)c).ReadOnly = true;
if (c is DropDownList)
((DropDownList)c).Enabled = false;
if (c is DateTextBox)
((TextBox)c).ReadOnly = true;
if (c is TimeTextBox)
((TextBox)c).ReadOnly = true;
if (c is MarketSegmentDropDownList)
((DropDownList)c).Enabled = false;
if (c is MarketSegmentDetailDropDownList)
((DropDownList)c).Enabled = false;
if (c is ZipCodeTextBox)
((TextBox)c).ReadOnly = true;
} |
Merci :yaisse2: