Home > Net >  Add multiple checkbox in the Winfrom datagridview columns
Add multiple checkbox in the Winfrom datagridview columns

Time:11-06

Want a column in the datagridview add show multiple checkbox
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 difficult

CodePudding 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:

reference 1st floor sprc_lcl 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;
before also have user controls, but change the column width, don't know how to change the control size

CodePudding user response:

reference 4 floor QQ83667664 response:
Quote: reference 1st floor sprc_lcl 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;
before also have user controls, but change the column width, don't know how to change the control size


Implement a DataGridViewCheckboxListColumn and DataGridViewCheckBoxListCell,

CodePudding user response:

reference 5 floor icoolno1 reply:
Quote: refer to 4th floor QQ83667664 response:
Quote: refer to 1st floor sprc_lcl 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;
before also have user controls, but change the column width, don't know how to change the control size


Implement a DataGridViewCheckboxListColumn and DataGridViewCheckBoxListCell
I was writing such a class, but how to achieve in this class but change the column width, I don't know how to change the control size?

CodePudding user response:

Reference: https://blog.csdn.net/C_gyl/article/details/85095021
  •  Tags:  
  • C#
  • Related