“继承DataGridViewCheckBoxCell时,即使类没有实现任何内容时,”单元格的格式化值具有错误的类型“错误

时间:2018-05-29 01:26:21

标签: c# datagridview datagridviewcolumn

代码是

using System;
using System.Windows.Forms;
namespace MyDataGridView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckBoxColumn col = new CheckBoxColumn();
            //DataGridViewCheckBoxColumn col = new DataGridViewCheckBoxColumn();
            col.ValueType = typeof(bool);
            dataGridView1.Columns.Add(col);                
            dataGridView1.Rows.Add(new object[]{true});
        }
    }
    public class CheckBoxCell : DataGridViewCheckBoxCell
    {
        /*public CheckBoxCell()
        {
            ThreeState = false;
            TrueValue = 1;
            FalseValue = 0;
        }*/
    }
    public class CheckBoxColumn : DataGridViewColumn
    {
        public CheckBoxColumn()
        {
            CellTemplate = new CheckBoxCell();
        }
    }
}

Form1有一个名为dataGridView1

的datagridview

当我将'col'变量更改为DataGridViewCheckBoxColumn时,一切正常

我将类子类化为在单元格上提供一些自定义绘画

0 个答案:

没有答案