Version

Print(UltraGridLayout) Method

Initiates the creation of a printed report of the grid data.
Syntax
'Declaration
 
Public Overloads Sub Print( _
   ByVal layout As UltraGridLayout _
) 
public void Print( 
   UltraGridLayout layout
)

Parameters

layout
Optional DisplayLayout object
Remarks

The Print method initiates a print job. Invoking this method triggers the process of preparing a printed report based on the data in the grid and sending it to the printer. This process has several steps and involves interaction between print-specific objects and events within the control.

When you invoke this method, you specify a Layout object that controls the formatting of the grid data when printed. The Layout object gives you the opportunity to create a custom-formated report based on the data in teh grid, applying different attributes such as fonts, colors and arrangement of data specifically for the printed page.

When the print job begins, the InitializePrint event occurs. This event receives a PrintDocument object that contains information about the print job. You examine and change the properties of this object to provide feedback for the user and control the look of the printed output.

Example
Following code shows how to print the UltraGrid and makes use of BeforePrint event to show a confirmation dialog before proceeding with printing the UltraGrid.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid
Imports System.Drawing.Printing

  Private Sub Button16_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button16.Click

      ' Following code shows a print preview dialog and then prints the UltraGrid.

      Try
          ' Optinally show the print preview dialog.
          Me.ultraGrid1.PrintPreview()

          ' Calling print causes the UltraGrid to send the print job to the printer.
          Me.ultraGrid1.Print()
      Catch exc As Exception
          ' Catch any exceptions that may get thrown and let the user know.
          MessageBox.Show("Error occured while printing." & vbCrLf & exc.Message, "Error printing", _
                                      MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try

  End Sub

  Private Sub UltraGrid1_BeforePrint(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CancelablePrintEventArgs) Handles ultraGrid1.BeforePrint

      ' Following code shows a message box giving the user a last chance to cancel printing the 
      ' UltraGrid.
      Dim result As DialogResult = MessageBox.Show("Proceed with printing ?", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
      If DialogResult.Cancel = result Then e.Cancel = True

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;
   using System.Drawing.Printing;

private void button16_Click(object sender, System.EventArgs e)
{	

	// Following code shows a print preview dialog and then prints the UltraGrid.

	try
	{
		// Optinally show the print preview dialog.
		this.ultraGrid1.PrintPreview( );

		// Calling print causes the UltraGrid to send the print job to the printer.
		this.ultraGrid1.Print( );			
	}
	catch ( Exception exc )
	{
		// Catch any exceptions that may get thrown and let the user know.
              
		MessageBox.Show( "Error occured while printing.\n" + exc.Message, "Error printing", 
			MessageBoxButtons.OK, MessageBoxIcon.Error );
	}

}
		
private void ultraGrid1_BeforePrint(object sender, Infragistics.Win.UltraWinGrid.CancelablePrintEventArgs e)
{

	// Following code shows a message box giving the user a last chance to cancel printing the 
	// UltraGrid.

	DialogResult result = MessageBox.Show( "Proceed with printing ?", "Confirm", 
		MessageBoxButtons.OKCancel, MessageBoxIcon.Question );
	
	if ( DialogResult.Cancel == result )
		e.Cancel = true;

}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also