RadPrintDocument does not print GridView selection

1 Answer 39 Views
General Discussions GridView
Julian
Top achievements
Rank 1
Julian asked on 03 Jul 2023, 12:52 PM

Hi,

I have a RadGridView that is the AssociatedObject of a RadPrintDocument that I want to print via a PrintDialog:

private PrintDialog printDialog;
RadPrintDocument doc = new RadPrintDocument
{
	AssociatedObject = radGridHistorie
};

printDialog.Document = doc;
printDialog.AllowSelection = true;

if (printDialog.ShowDialog() == DialogResult.OK)
{
	doc.Print();
}

 

If I select "All" in the PrintDialog, all entries are printed on the document.

If I select "Selection" in the printDialog after having Rows selected in the GridView, no entries are on the printed document.

What is wrong?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Jul 2023, 01:25 PM

Hello, Julian,

The PrintDialog.AllowSelection property controls whether the Selection option button is enabled. Additional information is available here:

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.printdialog.allowselection?view=windowsdesktop-7.0 

RadGridView is expected to print all of its contained rows no matter if the row is selected or not. If you want to print only the selected rows, the appropriate way is to create a dummy RadGridView populated only with the data from the selected rows. Then, print this dummy grid.

An alternative solution is to make the not selected rows invisible and thus, they will be skipped during printing. A sample approach is demonstrated in the following code snippet:  

        private void RadForm1_Load(object sender, EventArgs e)
        { 
            this.productsTableAdapter.Fill(this.nwindDataSet.Products);

            this.radGridView1.BestFitColumns();
            this.radGridView1.MultiSelect = true;
        }

        private PrintDialog printDialog;

        private void radButton1_Click(object sender, EventArgs e)
        {
            List<GridViewRowInfo> list = new List<GridViewRowInfo>();
            foreach (GridViewRowInfo rowInfo in this.radGridView1.Rows)
            {
                if (rowInfo.IsSelected == false)
                {
                    rowInfo.IsVisible = false;
                    list.Add(rowInfo);
                }
            }
            
            printDialog = new PrintDialog();
            RadPrintDocument doc = new RadPrintDocument
            {
                AssociatedObject = this.radGridView1
            };

            printDialog.Document = doc;
            printDialog.AllowSelection = true;

            if (printDialog.ShowDialog() == DialogResult.OK)
            {
                doc.Print();
            }

            foreach (GridViewRowInfo rowInfo in list)
            {
                rowInfo.IsVisible = true;
            }
        }

Feel free to use this approach which suits your requirements best.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
General Discussions GridView
Asked by
Julian
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or