Code Bye

DatagridView 怎么添加DataGridViewCheckBoxColumn列

起因:将 作为数据源加到DatagridView时,DatagridView正常显示。
代码如下:
            this.DayPlan_DGView.DataSource = mDataSet_CyclePlan.Tables[0];
            this.DayPlan_DGView.Columns[0].FillWeight = 85;     //段号
            this.DayPlan_DGView.Columns[1].FillWeight = 65;    //开始时间:小时
            this.DayPlan_DGView.Columns[2].FillWeight = 65;     //开始时间:分钟
            this.DayPlan_DGView.Columns[3].FillWeight = 330;   
            this.DayPlan_DGView.Columns[4].FillWeight = 100;   

此时运行正常.如下图

然后本人想在这个数据表中添加一列,带CheckBox的列:DataGridViewCheckBoxColumn列
代码如下:

        DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
            this.DayPlan_DGView.DataSource = mDataSet_CyclePlan.Tables[0];
          //  this.DayPlan_DGView.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;  
            this.DayPlan_DGView.Columns[0].FillWeight = 85;     //段号
            this.DayPlan_DGView.Columns[1].FillWeight = 65;    //开始时间:小时
            this.DayPlan_DGView.Columns[2].FillWeight = 65;     //开始时间:分钟
            this.DayPlan_DGView.Columns[3].FillWeight = 330;   
            this.DayPlan_DGView.Columns[4].FillWeight = 100;   
            column.HeaderText = "选中";
            column.Name = "";
            column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
            column.FlatStyle = FlatStyle.Standard;
            column.ThreeState = true;
            column.CellTemplate = new DataGridViewCheckBoxCell();
            column.CellTemplate.Style.BackColor = Color.Beige;
            this.DayPlan_DGView.Columns.Insert(4, column);

此时显示如下错误:

讨教本人应该说怎么做。

解决方案

40

http://www.cnblogs.com/moss_tan_jun/archive/2011/04/06/2007319.html

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明DatagridView 怎么添加DataGridViewCheckBoxColumn列