您的位置:首页 > 其它

动态添加dev CheckEdit控件,以及删除。事件处理

2013-09-24 15:35 465 查看
//删除原有动态生成的控件,原本这个容器中只有4个控件,其他的都是动态生成。如后期有添加控件,这里的4应做修改
int count = navBarGroupControlContainer4.Controls.Count-4;
for (int j = 0; j < count; j++)
{
navBarGroupControlContainer4.Controls.RemoveByKey(String.Format("RE{0}", j));
}
//更新格式checkEdit
if (this.printModule.GetReportFormat(nIndex).GetSettingCount() > 0)
{//动态添加
for (int i = 0;i<this.printModule.GetReportFormat(nIndex).GetSettingCount();i++)
{
DevExpress.XtraEditors.CheckEdit RecordEdit = new DevExpress.XtraEditors.CheckEdit();
RecordEdit.Parent = this.navBarGroupControlContainer4;//绑定到容器,不然不显示的
RecordEdit.Checked = this.printModule.GetReportFormat(nIndex).GetSetting(i);
RecordEdit.Text = this.printModule.GetReportFormat(nIndex).GetSettingString(i);

RecordEdit.Location = new Point(5, memoReport.Bottom + 19 * i+10);
RecordEdit.Size = new System.Drawing.Size(183, 19) ;
RecordEdit.Visible = true;
RecordEdit.CheckedChanged += new System.EventHandler(this.ReportEdit_CheckedChanged);
RecordEdit.Name = String.Format("RE{0}", i);//做好标记,以便删除和事件处理
}

}

private void ReportEdit_CheckedChanged(object sender, EventArgs e)
{
int nIndex = this.printModule.SelReportIndex;
string name = ((DevExpress.XtraEditors.CheckEdit)sender).Name;
bool b = ((DevExpress.XtraEditors.CheckEdit)sender).Checked;
int index = System.Int32.Parse(name.Trim(("RE").ToCharArray()));根据动态创建的时候做的标记,获得隐藏在上面的Index
this.printModule.GetReportFormat(nIndex).WriteSetting(index, b);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: