We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

printing Static cells

Thread ID:





26085 Mar 14,2005 05:38 AM Mar 14,2005 06:32 AM Windows Forms 1
Tags: GridControl
Administrator [Syncfusion]
Asked On March 14, 2005 05:38 AM

I have a gridcontrol that has cells with pushbutton. When i am printing this directly i am getting those cells in print preview. But i am copying the original grid to a printgrid. When i do this, for the first row (only for the first row) the push button doesnt appear in the print preview, but when it is printed, it appears correctly.How do i solve this problem. I have given a sample code showing this problem. using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using Syncfusion.Windows.Forms.Grid; namespace WindowsApplication1 { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private Syncfusion.Windows.Forms.Grid.GridControl gridControl1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // gridControl1.RowCount = 2; gridControl1.ColCount = 2; } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.gridControl1 = new Syncfusion.Windows.Forms.Grid.GridControl(); ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(576, 376); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(88, 32); this.button1.TabIndex = 0; this.button1.Text = "Print Preview"; this.button1.Click += new System.EventHandler(this.button1_Click); // // gridControl1 // this.gridControl1.Location = new System.Drawing.Point(40, 24); this.gridControl1.Name = "gridControl1"; this.gridControl1.Size = new System.Drawing.Size(736, 352); this.gridControl1.TabIndex = 1; this.gridControl1.Text = "gridControl1"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(880, 429); this.Controls.Add(this.gridControl1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { gridControl1.BaseStylesMap["Standard"].StyleInfo.Font.Unit=GraphicsUnit.World; gridControl1[1,1].CellType="PushButton"; gridControl1[1,1].Description = "Show"; gridControl1[1,2].Font.Facename=" courier new"; gridControl1[1,2].Font.Size=10; gridControl1[1,2].CellValue = "This is going to be (This text is to increase the width)a multiple line in the grid "+System.Environment.NewLine+ "This is the second line in the cell"+System.Environment.NewLine+ "Check this line is printed correctly"; gridControl1[2,1].CellType="PushButton"; gridControl1[2,1].Description = "Show"; gridControl1.ColWidths.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Col(2),Syncfusion.Windows.Forms.Grid.GridResizeToFitOptions.IncludeHeaders); gridControl1.RowHeights.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Row(1),Syncfusion.Windows.Forms.Grid.GridResizeToFitOptions.IncludeHeaders); } private System.Drawing.Printing.PrintDocument GetDoc() { GridControl printGrid=new GridControl(); //printGrid.BaseStylesMap["Standard"].StyleInfo.Font.Unit=GraphicsUnit.Point; printGrid.RowCount=gridControl1.RowCount; printGrid.ColCount=gridControl1.ColCount; for( int row=0; row<=gridControl1.RowCount; row++) { printGrid.RowHeights[row]=gridControl1.RowHeights[row]; for( int col=0; col<=gridControl1.ColCount; col++) { // Copy the visible features of the cell to the print cell GridStyleInfo printCell = printGrid[row,col]; GridStyleInfo cell = gridControl1[row,col]; printCell.Text = cell.Text; printCell.BackColor = cell.BackColor; printCell.CellType = cell.CellType; printCell.TextColor = cell.TextColor; printCell.Font = cell.Font; printCell.Description=cell.Description; } } printGrid.ColWidths.ResizeToFit(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Col(2),Syncfusion.Windows.Forms.Grid.GridResizeToFitOptions.IncludeHeaders); Syncfusion.Windows.Forms.Grid.GridPrintDocument doc = new Syncfusion.Windows.Forms.Grid.GridPrintDocument(printGrid, true); return doc; } private void button1_Click(object sender, System.EventArgs e) { System.Drawing.Printing.PrintDocument printDoc = GetDoc(); System.Windows.Forms.PrintPreviewDialog pdlg = new PrintPreviewDialog(); pdlg.Document = printDoc; pdlg.ShowDialog(); } } }

Administrator [Syncfusion]
Replied On March 14, 2005 06:32 AM

The grid has to be parented to something. GridControl printGrid=new GridControl(); printGrid.Visible = false; //this.Controls.Add(printGrid); printGrid.Parent = this;


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.