110,535
社区成员
发帖
与我相关
我的任务
分享
class datagridviewCheckboxHeaderCell : DataGridViewColumnHeaderCell
{
Point checkBoxLocation;
Size checkBoxSize;
bool _checked = false;
Point _cellLocation = new Point();
System.Windows.Forms.VisualStyles.CheckBoxState _cbState =
System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
public event datagridviewcheckboxHeaderEventHander OnCheckBoxClicked;
//绘制列头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,
dataGridViewElementState, value,
formattedValue, errorText, cellStyle,
advancedBorderStyle, paintParts);
Point p = new Point();
Size s = CheckBoxRenderer.GetGlyphSize(graphics,
System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
p.X = cellBounds.Location.X +
(cellBounds.Width / 2) - (s.Width / 2) - 1;//列头checkbox的X坐标
p.Y = cellBounds.Location.Y +
(cellBounds.Height / 2) - (s.Height / 2);//列头checkbox的Y坐标
_cellLocation = cellBounds.Location;
checkBoxLocation = p;
checkBoxSize = s;
if (_checked)
_cbState = System.Windows.Forms.VisualStyles.
CheckBoxState.CheckedNormal;
else
_cbState = System.Windows.Forms.VisualStyles.
CheckBoxState.UncheckedNormal;
CheckBoxRenderer.DrawCheckBox
(graphics, checkBoxLocation, _cbState);
}
}
protected override void Paint(
Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,
int rowIndex, DataGridViewElementStates cellState,
object value, object formattedValue, string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
// Use the base method to paint the default appearance.
base.Paint(graphics, clipBounds, cellBounds, rowIndex,
cellState, value, formattedValue,
errorText, cellStyle, advancedBorderStyle, paintParts);
// Retrieve the current button bounds.
Rectangle buttonBounds = DropDownButtonBounds;
// Continue only if the buttonBounds is big enough to draw.
if (buttonBounds.Width < 1 || buttonBounds.Height < 1) return;
if (Application.RenderWithVisualStyles)
{
ComboBoxState state = ComboBoxState.Normal;
//if (dropDownListBoxShowing)
//{
// state = ComboBoxState.Pressed;
//}
ComboBoxRenderer.DrawDropDownButton(
graphics, buttonBounds, state);
}
else
{
// Determine the pressed state in order to paint the button
// correctly and to offset the down arrow.
Int32 pressedOffset = 0;
PushButtonState state = PushButtonState.Normal;
//if (dropDownListBoxShowing)
//{
// state = PushButtonState.Pressed;
// pressedOffset = 1;
//}
ButtonRenderer.DrawButton(graphics, buttonBounds, state);
graphics.DrawPolygon(SystemPens.ControlText, new Point[] {
new Point(
buttonBounds.Width / 2 +
buttonBounds.Left - 1 + pressedOffset,
buttonBounds.Height * 3 / 4 +
buttonBounds.Top - 1 + pressedOffset),
new Point(
buttonBounds.Width / 4 +
buttonBounds.Left + pressedOffset,
buttonBounds.Height / 2 +
buttonBounds.Top - 1 + pressedOffset),
new Point(
buttonBounds.Width * 3 / 4 +
buttonBounds.Left - 1 + pressedOffset,
buttonBounds.Height / 2 +
buttonBounds.Top - 1 + pressedOffset)
});
}
}
string sql = "select ck_name from WH_cangku";
DataSet ds = new DataSet();
ds = Maticsoft.DBUtility.DbHelperSQL.Query(sql);//这里是执行sql语句的
this.Column19.DataSource = ds.Tables[0];
this.Column19.DisplayMember = "ck_name";