代码是
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时,一切正常
我将类子类化为在单元格上提供一些自定义绘画