我在layoutcontrol1下的表单上有很多Devexpress控件。我用了 下面的代码迭代每个控件并在用户单击“清除”按钮时清除现有数据。但是,它不适用于LookupEdit(将EditValue设置为0)和CheckedListBoxControl(取消选中所有选定的项目)。
foreach (Control c in layoutControl1.Controls)
{
if (c.GetType() == typeof(TextEdit) || c.GetType()==typeof(MemoEdit))
c.Text = String.Empty;
if (c.GetType() == typeof(LookUpEdit))
c.EditValue = 0; //doesn't have EditValue property
if (c.GetType() == typeof(CheckedListBoxControl))
c.CheckedItems = CheckState.Unchecked; //doesn't have such property
}
有什么建议吗?
答案 0 :(得分:1)
试试以下内容:
foreach(Control c in layoutControl1.Controls) {
var edit = c as DevExpress.XtraEditors.BaseEdit; // base class for DX editors
if(edit != null)
edit.EditValue = null;
var listBox = c as DevExpress.XtraEditors.CheckedListBoxControl;
if(listBox != null)
listBox.UnCheckAll();
}