The System.Drawing.Printing.PrintDocument class has the Print mode which will print your document directly to the printer.  The Infragistics NetAdvantage suite has a couple of subclasses of PrintDocument.  One of them is the Infragistics.Win.UltraWinGrid.UltraGridPrintDocument which is designed to print the contents of a specific data grid.  The problem I ran into with the PrintDocument is that it prints to the default printer.  There is no prompt for a different printer.  However, as it turns out getting those details is very simple.

There are two ways to approach the problem.  You can have the user specify the settings and then use those settings for every call you make until the settings are specifically changed, or you can prompt when a print request is made.  I chose the latter, because it makes sense for my application and all you have to do is add a handler for the BeginPrint event of the PrintDocument.

private void ultraGridPrintDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)

{

    /* include this check otherwise the dialog will be

    * displayed when a print preview is shown */

    if (e.PrintAction == System.Drawing.Printing.PrintAction.PrintToPreview)

        return;

 

    using (PrintDialog dialog = new PrintDialog())

    {

        /* record the current printer settings for the document;

        * otherwise, the default system settings are used */

        dialog.PrinterSettings = ultraGridPrintDocument1.PrinterSettings;

 

        if (dialog.ShowDialog(this) == DialogResult.OK)

            ultraGridPrintDocument1.PrinterSettings = dialog.PrinterSettings;

        else

            e.Cancel = true;

    }

}

 

The Infragistics NetAdvantage suite also has a preview dialog named Infragistics.Win.Printing.UltraPrintPreviewDialog.  This class is similar to the one provided by the Framework, but it uses Infragistics controls and has a matching look-and-feel.  The solution provided also works for using the print preview dialog.  The one thing of note is that the print preview dialog allows the printer settings to be changed, but it's not direct (File --> Page Setup, click Printer, change settings, click OK).  I ignore this possibility and display the dialog, because it's not something that will be an issue to my users.