前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >c# 动态产生控件 注册动态控件事件

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

作者头像
乔达摩@嘿
发布2020-09-11 14:45:38
8160
发布2020-09-11 14:45:38
举报
文章被收录于专栏:嘿dotNet

用CheckEdit演示 其他控件类推

代码语言:javascript
复制
                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++;
                }

下面是单选框值改变事件

代码语言:javascript
复制
  /// <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

            }

        }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014-06-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档