Category / Section
How to display the ReadOnly custom CheckBox while on PrintPreview in WinForms GridGroupingControl?
1 min read
Show custom checkbox while on print preview
You can display the ReadOnly custom CheckBox by setting the CellType of a column style as CheckBox dynamically while printing the Grid by using the QueryCellStyleInfo event.In the following code example, the column, ParentDec is changed to CheckBox dynamically on PrintingMode.
C#
void TableDescriptor_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { if(this.gridGroupingControl1.TableControl.PrintingMode) { if(e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.Name == "ParentDec" && e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record) { e.Style.CellType = GridCellTypeName.CheckBox; e.Style.CellValue = ((int)e.Style.CellValue == 1); } } }
VB
Private Sub TableDescriptor_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs) If Me.gridGroupingControl1.TableControl.PrintingMode Then If e.TableCellIdentity.Column IsNot Nothing AndAlso e.TableCellIdentity.Column.Name = "ParentDec" AndAlso e.TableCellIdentity.DisplayElement.Kind Is DisplayElementKind.Record Then e.Style.CellType = GridCellTypeName.CheckBox e.Style.CellValue = (CInt(Fix(e.Style.CellValue)) = 1) End If End If End Sub
The following screenshots display ParentDec before and after changing to CheckBox:
Figure 1: ReadOnly ParentDec column before change
Figure 2: ReadOnly CheckBox column on print preview
Samples:
C#: Readonly-C#
VB: Readonly-VB