1.datagridview列头添加复选框
网上查了很多资料,大都是通过添加自绘复选框类来实现的。经验证效果不错。
/*****************************以下是自定义在datagridview列头绘制复选框*********************************************/
//定义继承于DataGridViewColumnHeaderCell的类,用于绘制checkbox,定义checkbox鼠标单击事件
public class datagridviewCheckboxHeaderCell : DataGridViewColumnHeaderCell
{
public delegate void HeaderEventHander(object sender, datagridviewCheckboxHeaderEventArgs e);
public event HeaderEventHander OnCheckBoxClicked;
Point checkBoxLocation;
Size checkBoxSize;
bool _checked = false;
Point _cellLocation = new Point();
System.Windows.Forms.VisualStyles.CheckBoxState _cbState =
System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
//绘制列头checkbox
protected override void Paint(System.Drawing.Graphics graphics,
System.Drawing.Rectangle clipBounds,
System.Drawing.Rectangle cellBounds,
int rowIndex,
DataGridViewElementStates dataGridViewElementState,
object value,
object formattedValue,
string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex,