Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
Printing only selected rows in Ultragrid
posted

Hi

I need to print only the selected rows of an Ultragrid using UltraPrintPreviewDialog.

Unfortunately the only answer I found points to a retired page:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7699&_ga=2.77319253.1167148253.1691374609-1130603967.1681458443&_gl=1*1gscb17*_ga*MTEzMDYwMzk2Ny4xNjgxNDU4NDQz*_ga_PN11HXDV6X*MTY5MTM4MDQyNy4xOS4xLjE2OTEzODA5NzguMjEuMC4w

I have tried hiding the rows that are not selected, but that does not prevent them from being printed.

When I use filters (in the UI), they are respected when printing.
But I can't figure out how to add a filter in C# that has a condition saying "row is selected".

Thanks for any suggestions

  • 1700
    Verified Answer
    Offline posted

    Hello Robert,

    This could be achieved by accessing the PrintLayout of the grid inside the InitializeRow, since the rows that are being printed are just a copy of the data set of the grid, not the real rows. Then the only thing that needs to be done is to check if the “real” row of the grid is selected and if it isn’t its print equivalent row should be hidden. It could be done with the following code:

     

    private void UltraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
            {
    
                UltraGrid grid = (UltraGrid)sender;
    
                // We only want to do this for print rows, not real rows in the on-screen grid.
                if (e.Row.Band.Layout.IsPrintLayout)
                {
                    // Get the real grid row from the print row.
                    UltraGridRow realGridRow = grid.GetRowFromPrintRow(e.Row);
    
                    // check if row is selected
    
                    if (!realGridRow.Selected)
                    {
                        // If the row is not selected hide it in the print preview
                        e.Row.Hidden = true;
                    }
                    
                }
            }

    I am also sending a gif that demonstrates what I have explained above:

    Please try this approach and let me know if you need any further assistance.

    Regards,
    Ivan Kitanov