foreach(Control gb in this.Controls)
{
if(gb is GroupBox)
{
foreach(Control tb in gb.Controls)
{
if(tb is TextBox)
{
//here is where you access all the textboxs.
}
}
}
}
foreach (var ctrl in gbDatabaseColumns.Controls)
{
if (ctrl is DevExpress.XtraEditors.TextEdit)
{
StoreTextEdit(config, (ctrl as DevExpress.XtraEditors.TextEdit));
}
}
foreach (Control txx in groupBox2.Controls)
{
if (txx is TextBox)
txx.Text = "";
if (txx is ComboBox)
txx.Text = "";
// if (txx is DateTimePicker)
// txx.Text = ""; Datetimepicker text can't be erased
}
5条答案
按热度按时间axr492tv1#
但是如果您已经定义了每个TextBox名称通过循环获取每个
TextBox
有什么意义呢?您可以定义一个
List<TextBox>
来保存每个TextBox
的引用,同时创建它们,然后只需通过List
来访问每个TextBox
。0yycz8jy2#
以下是我的建议:
或者将其置于一个循环中:
hmtdttj43#
请尝试以下代码,
lokaqttq4#
cnwbcb6i5#