//删除原有动态生成的控件,原本这个容器中只有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);
        }


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐