RadPrintDocument - Row Number

1 Answer 113 Views
GridView
Arun
Top achievements
Rank 2
Iron
Arun asked on 12 Jul 2021, 12:48 PM

Hi

Please Help

Language: VB.Net (VS2017)

Telerik Version: 2017.3.1017

I am printing from radGridView with RadPrintDocument. Please advise how to add row numbers in the printpreview/print document.

In radGridView, row number is there in Row Header.

Thanks

1 Answer, 1 is accepted

Sort by
1
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 13 Jul 2021, 12:27 PM

Hello, Arun,

According to the provided information, I suppose that you have displayed row numbers in the most left column in the grid which is the GridViewIndentColumn. In case you have a different set up it would be greatly appreciated if you can specify it. 

By default the indent column is not printed in the RadPrintDocument since usually, it doesn't display data. In your case, if you want to print the row numbers in the RadPrintDocument you should handle the PrintCellPaint event and paint the necessary info. This event allow you to access the cell and to paint in it whatever you need. More information is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/printing-support/events-and-customization#printcellpaint 

Please refer to the following code snippet:

Private Sub RadGridView1_PrintCellPaint(ByVal sender As Object, ByVal e As PrintCellPaintEventArgs)
    If TypeOf e.Row Is GridViewDataRowInfo AndAlso e.Column.FieldName = "Name" Then
        Dim rect As Rectangle = New Rectangle()
        rect.X = e.CellRect.X - 25
        rect.Y = e.CellRect.Y
        rect.Width = 25
        rect.Height = e.CellRect.Height
        Dim sf As StringFormat = New StringFormat()
        sf.LineAlignment = StringAlignment.Center
        sf.Alignment = StringAlignment.Center
        e.Graphics.DrawString(e.Row.Index.ToString(), Control.DefaultFont, Brushes.Black, rect, sf)
        e.Graphics.DrawRectangle(Pens.Black, rect)
    End If
End Sub

Note, that this is a sample approach and may not cover all possible cases. Feel free to modify and extend this example in a way to achieve the desired look.

If you need to align the displayed column in the print document you can adjust the RadPrintDocument.DefaultPageSettings.Margins.Left property before printing.

I hope this helps. If you have other questions please let me know.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Arun
Top achievements
Rank 2
Iron
commented on 13 Jul 2021, 12:51 PM

Thank you very much. Just amended e.Row.Index + 1 to start from 1.
Tags
GridView
Asked by
Arun
Top achievements
Rank 2
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or