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
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:
PrivateSub RadGridView1_PrintCellPaint(ByVal sender AsObject, ByVal e As PrintCellPaintEventArgs)
IfTypeOf e.Row Is GridViewDataRowInfo AndAlso e.Column.FieldName = "Name"ThenDim 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)
EndIfEndSub
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/.