As shown in figure:
Through redrawing can show multiple chekbox, now the problem is 1, narrow stretch column, the checkbox ran out, which is a great god know how to change, let it stretch column chekbox shrink or hidden in the column, for each checkbox question 2. How to add the click event
Protected override void Paint (System. Drawing. The Graphics Graphics,
System, Drawing a Rectangle clipBounds, System. Drawing. The Rectangle cellBounds,
Int rowIndex, DataGridViewElementStates cellState, object value,
Object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
Var uu=this. ColumnIndex;
If (uu==4)
{
Var ChecName=value;
If (the value!=null) {
Base. Paint (graphics, clipBounds cellBounds, rowIndex,
CellState, value, formattedValue errorText,
CellStyle advancedBorderStyle, paintParts);
A Rectangle textRectangleValue=https://bbs.csdn.net/topics/new a Rectangle (); if (! Enclosing ShowOriginal)
{
//draw the background
If ((paintParts & amp; DataGridViewPaintParts. Background)==DataGridViewPaintParts. Background)
{
SolidBrush cellBackground=new SolidBrush (cellStyle BackColor);
Graphics. FillRectangle (cellBackground cellBounds);
CellBackground. The Dispose ();
}
//draw a border
If ((paintParts & amp; DataGridViewPaintParts. Border)==DataGridViewPaintParts. Border)
{
PaintBorder (graphics, clipBounds cellBounds cellStyle, advancedBorderStyle);
}
System. Drawing. The Font myFont=new System. Drawing. The Font (" tahoma ", 9 f, System. Drawing. FontStyle. Underline, System. Drawing. The GraphicsUnit. Point, ((byte) (134)));
SizeF vSizeF=graphics. MeasureString (" new ", myFont);
Int dStrLength=the Convert. ToInt32 (math.h between (vSizeF. Width));
TextRectangleValue. X=0;
for (int j=0; j<5; J++) {
The Size Size=CheckBoxRenderer. GetGlyphSize (graphics, state);
Point center=new Point (cellBounds. X + + 15 + dStrLength * j, cellBounds. Y);
Center. X +=3;
Center. Y +=(cellBounds. Height - size. Height)/2;
TextRectangleValue. X=center. X + 15;
TextRectangleValue. Y=cellBounds. Y;
TextRectangleValue. Width=cellBounds. Width - CheckBoxRenderer. GetGlyphSize (graphics, CheckBoxState. UncheckedNormal). The Width;
TextRectangleValue. Height=cellBounds. Height
- (cellBounds. Height - CheckBoxRenderer. GetGlyphSize (graphics, CheckBoxState. UncheckedNormal). Width)/2-1;
State=CheckBoxState. UncheckedNormal;
CheckBoxRenderer. DrawCheckBox (graphics, center, textRectangleValue, "GGG SystemFonts. DefaultFont, TextFormatFlags. Bottom, false, the state);
}
CodePudding user response:
Did you do this far, again under the divergent thinking about, give you an idea:Custom user controls and user controls and then put a fixed size of the panel, the user control properties with rows of data binding, throw all the checkbox to the user controls on a panel, events can literally;;
Datagridview don't have a a checkbox added;; Just add a user control,,, and then the column width change (redraw?) Changes the size of the user control;
CodePudding user response:
The WPF good implementation, with this, it's too difficultCodePudding user response:
Then at your code, you this redraw method is not suitable, just draw out, no Mao Yong;Need examples of control, then control assigned to the corresponding position
CodePudding user response: