winform,DataGridView绑定数据后更改列属性、动态创建(用一个控件显示多表适用)

          DataGridView 特效 = new DataGridView();
          string[] 列名 = { "直线", "炸弹", "骷髅", "礼盒" }, 说明 = {"消除一列所有元素","消除4×4范围元素","消除所有指定元素","随机赠送三种特效一个"};
            int 列数 = 0;
            foreach (string 元素 in 列名)
            {
                DataGridViewImageColumn 新图列 = new DataGridViewImageColumn();
                新图列.HeaderText = 元素;
                特效.Columns.Add(新图列);
            }
            特效.Rows.Add();
            foreach (string 元素 in 说明)
            {
                特效.Rows[0].Cells[列数].Value = new Bitmap(24, 24);
                特效.Rows[0].Cells[列数++].ToolTipText = 元素;
            }
            特效.Rows.Add(); 列数 = 0;
            foreach (string 元素 in 列名)
            {
                DataGridViewTextBoxCell 文本列 = new DataGridViewTextBoxCell();
                特效.Rows[1].Cells[列数] = 文本列;
                特效.Rows[1].Cells[列数++].Value = "0";
            }

 

 

 

        private void 改变列属性()
        {
            for (int 行 = 0; 行 < 编辑控表.RowCount - 1; 行++)
            {
                for (int 列 = 0; 列 < 编辑控表.ColumnCount; 列++)
                {
                    DataGridViewLinkCell 超链接列 = new DataGridViewLinkCell();
                    if (编辑控表.Rows[行].Cells[列].Value.ToString().IndexOf("http://") == 0)
                        编辑控表.Rows[行].Cells[列] = 超链接列;
                }
            }
        }

 

        private void 创建数据显示(string[] 表列名)
        {
            编辑控表.Columns.Clear();
            foreach (string 元素 in 表名)
            {
                DataGridViewTextBoxColumn 列 = new DataGridViewTextBoxColumn();
                列.HeaderText = 元素;
                列.DataPropertyName = 元素;
                编辑控表.Columns.Add(列);
            }
        }

 

                string[] 动态显示列 = null;
                动态显示列 = new string[] { "归属", "姓名", "生日", "性别", "关系" }; 创建数据显示(创建);
                动态显示列 = new string[] { "总类", "别类", "子类", "标题", "内容" }; 创建数据显示(创建); 
                动态显示列 = new string[] { "智力值", "情绪值", "体力值", "均值", "相隔天数", "提示内容", "心情日记", "日期" }; 创建数据显示(创建);
WinForm DataGridView 行焦点不改变的情况下提交数据:
if (DataGridView.IsCurrentCellDirty) DataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
bindingSource.EndEdit();

            //列名.Select(aa => 特效.Columns.Add(aa, aa)).ToArray();
            列名.Select(aa => 特效.Columns.Add(new DataGridViewImageColumn())).ToArray();
            特效.Rows.Add();
            特效.Rows[0].Cells.Cast<DataGridViewCell>().Select((aa, id) => aa.OwningColumn.HeaderText = 列名[id]).ToArray();
            特效.Rows[0].Cells.Cast<DataGridViewCell>().Select(aa => aa.Value = new Bitmap(24, 24)).ToArray();
            特效.Rows[0].Cells.Cast<DataGridViewCell>().Select((aa, id) => aa.ToolTipText = 说明[id]).ToArray();


            特效.Columns.Insert(特效.Columns.Count , new DataGridViewCheckBoxColumn());
            特效.Rows[0].Cells[特效.Columns.Count - 1].Value = true;
            特效.Rows[1].Cells[特效.Columns.Count - 1].Value = true;



  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值