You can create a custom print preview and customize how your grid will appear when printed. You can do this using the Init method. To override properties like FormBorderStyle, MaximizeBox, MinimizeBox, ControlBox and so on of a Form inherited from C1.Win.C1TrueDBGrid.PrintForm, override the Init method of the PrintForm. First call the base.Init(), then set the properties you want.
Complete the following steps:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
FillGrid() |
To write code in C#
C# |
Copy Code
|
---|---|
FillGrid(); |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub FillGrid() Dim maxrows As Integer = 5 Dim dt As New DataTable("testdatatable") Dim dc As DataColumn Dim dr As DataRow ' set up an integer column dc = New DataColumn() dc.DataType = System.Type.[GetType]("System.DateTime") dc.ColumnName = "DT1" dt.Columns.Add(dc) ' do string dc = New DataColumn() dc.DataType = System.Type.[GetType]("System.DateTime") dc.ColumnName = "DT2" dt.Columns.Add(dc) ' do string dc = New DataColumn() dc.DataType = System.Type.[GetType]("System.DateTime") dc.ColumnName = "DT3" dt.Columns.Add(dc) Dim rnd As New Random() For i As Integer = 0 To maxrows - 1 dr = dt.NewRow() dr("DT1") = DateTime.Now.AddDays(i) dr("DT2") = DateTime.Now.AddMonths(i) dr("DT3") = DateTime.Now.AddYears(i) dt.Rows.Add(dr) Next Me.C1TrueDBGrid1.DataSource = dt Me.C1TrueDBGrid1.Columns("DT1").EnableDateTimeEditor = True Me.C1TrueDBGrid1.Columns("DT2").EnableDateTimeEditor = True Me.C1TrueDBGrid1.Columns("DT3").EnableDateTimeEditor = True End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void FillGrid() { int maxrows = 5; DataTable dt = new DataTable("testdatatable"); DataColumn dc; DataRow dr; // set up an integer column dc = new DataColumn(); dc.DataType = System.Type.GetType("System.DateTime"); dc.ColumnName = "DT1"; dt.Columns.Add(dc); // do string dc = new DataColumn(); dc.DataType = System.Type.GetType("System.DateTime"); dc.ColumnName = "DT2"; dt.Columns.Add(dc); // do string dc = new DataColumn(); dc.DataType = System.Type.GetType("System.DateTime"); dc.ColumnName = "DT3"; dt.Columns.Add(dc); Random rnd = new Random(); for (int i = 0; i < maxrows; i++) { dr = dt.NewRow(); dr["DT1"] = DateTime.Now.AddDays(i); ; dr["DT2"] = DateTime.Now.AddMonths(i); dr["DT3"] = DateTime.Now.AddYears(i); dt.Rows.Add(dr); } this.c1TrueDBGrid1.DataSource = dt; this.c1TrueDBGrid1.Columns["DT1"].EnableDateTimeEditor = true; this.c1TrueDBGrid1.Columns["DT2"].EnableDateTimeEditor = true; this.c1TrueDBGrid1.Columns["DT3"].EnableDateTimeEditor = true; } |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Public Class PrintForm1 Inherits C1.Win.C1TrueDBGrid.PrintForm |
To write code in C#
C# |
Copy Code
|
---|---|
public partial class PrintForm1 : C1.Win.C1TrueDBGrid.PrintForm |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Protected Overrides Sub Init() MyBase.Init() FormBorderStyle = FormBorderStyle.Sizable Me.ControlBox = True Me.MinimizeBox = False Me.MaximizeBox = False End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
protected override void Init() { base.Init(); FormBorderStyle = FormBorderStyle.Sizable; this.ControlBox = true; this.MinimizeBox = false; this.MaximizeBox = false; } |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
C1TrueDBGrid1.PrintInfo.PreviewFormClassName = "ProjectName.PrintForm" C1TrueDBGrid1.PrintInfo.PrintPreview() |
To write code in C#
C# |
Copy Code
|
---|---|
c1TrueDBGrid1.PrintInfo.PreviewFormClassName = "ProjectName.PrintForm1"; c1TrueDBGrid1.PrintInfo.PrintPreview(); |
Run the application and notice the application appears with a button and grid displaying data. Click the Preview button and observe that a customized print preview form appears. The form only includes the Close button and not the Minimize and Maximize buttons.