Loading

c# 动态产生控件 注册动态控件事件

用CheckEdit演示 其他控件类推


                CheckEdit AllSele = new CheckEdit();
                AllSele.Location = new System.Drawing.Point(10, 16);
                AllSele.Text = "全选";
                this.groupBox5.Controls.Add(AllSele);
                AllSele.CheckedChanged += new EventHandler(AllSele_CheckedChanged);

                int i = 2;
                int x = 10;
                while (i < colCount)
                {
                    CheckEdit cEt = new CheckEdit();
                    cEt.Location = new System.Drawing.Point(x += 75, 16);
                    cEt.Text = dt.Columns[i].ColumnName;
                    cEt.Name = cEt.Text;
                    this.groupBox5.Controls.Add(cEt);
                    cEt.CheckedChanged += new EventHandler(cEt_CheckedChanged);
                    i++;
                }

下面是单选框值改变事件


  /// <summary>
        /// 单选框处理事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cEt_CheckedChanged(object sender, EventArgs e)
        {
            CheckEdit ce = (CheckEdit)sender;

            if (flag)
            {
                //小数据  string te = ce.Name;    //view.Columns[ce.Name + "_YB"].Name;
                //cpggcc.Visible = true;
                view.Columns["PART"].OwnerBand = cpccbw;
                view.Columns["GC"].OwnerBand = cpgcfw;
                GridBand band = cpggcc.Children.AddBand(ce.Name);
                band.Name = ce.Name;
                GridBand yqBand = band.Children.AddBand("要求");
                GridBand ybBand = band.Children.AddBand("样板");
                GridBand ybcc = ybBand.Children.AddBand("尺寸");
                GridBand yqcc = yqBand.Children.AddBand("尺寸");
                view.Columns[ce.Name].Visible = true;
                view.Columns[ce.Name+"xx"].Visible = true;
                view.Columns[ce.Name].OwnerBand = yqcc;
                view.Columns[ce.Name+"xx"].OwnerBand = ybcc;
                view.Columns[ce.Name + "xx"].OptionsColumn.AllowEdit = true;
 
                string[] temp = new string[30];////
                for (int j1 = 0; j1 < view.Columns.Count; j1++)
                {
                    temp[j1] = view.Columns[j1].Name;
                }

                StyleCenter(band);
                StyleCenter(yqBand);
                StyleCenter(ybBand);
                StyleCenter(yqcc);
                StyleCenter(ybcc);
                flag = false;
            }
            else if (ce.Checked)
            {
                GridBand band = cpggcc.Children.AddBand(ce.Name);
                band.Name = ce.Name;
                GridBand yqBand = band.Children.AddBand("要求");
                GridBand ybBand = band.Children.AddBand("样板");
                GridBand ybcc = ybBand.Children.AddBand("尺寸");
                GridBand yqcc = yqBand.Children.AddBand("尺寸");
                view.Columns[ce.Name].OwnerBand = yqcc;
                view.Columns[ce.Name].Visible = true;
                view.Columns[ce.Name + "xx"].Visible = true;
                view.Columns[ce.Name].OptionsColumn.AllowEdit = true;
                view.Columns[ce.Name].OwnerBand = yqcc;
                view.Columns[ce.Name + "xx"].OwnerBand = ybcc;
                view.Columns[ce.Name + "xx"].OptionsColumn.AllowEdit = true;
                StyleCenter(band);
                StyleCenter(yqBand);
                StyleCenter(ybBand);
                StyleCenter(yqcc);
                StyleCenter(ybcc);
            }
            else
            {
                cpggcc.Children.Remove(cpggcc.Children[ce.Name]); //移除gridBand

            }

        }


posted @ 2014-06-06 09:44  乔达摩(嘿~)  阅读(232)  评论(0编辑  收藏  举报