I have a datagridview like this, as we can see there's total amount column. I want to print the datagridview, and make sum of total column at the end of the row in merged column. what should I do to make it work?
I am expecting the result must be like this
and I had try this
Using f As Font = New Font(cobacoba.dgv2.Font.FontFamily, cobacoba.dgv2.Font.Size)
Using br As New SolidBrush(Color.Black)
'draw the header
Dim CellLeftPos As Integer = 50
For col = 0 To cobacoba.dgv2.ColumnCount - 1
Dim CellValue As String = cobacoba.dgv2.Columns(col).HeaderText
Dim CellWidth = cobacoba.dgv2.Columns(col).Width + 50
e.Graphics.FillRectangle(Brushes.LightGray, CellLeftPos, CellTopPos, CellWidth, CellHeight)
e.Graphics.DrawString(CellValue, f, br, CellLeftPos + offset, CellTopPos + offset)
e.Graphics.DrawRectangle(Pens.Black, CellLeftPos, CellTopPos, CellWidth, CellHeight)
CellLeftPos += CellWidth
Next
CellTopPos += CellHeight
'draw the rows
For Row = LastRow To cobacoba.dgv2.RowCount - 1
CellLeftPos = 50
CellHeight = cobacoba.dgv2.Rows(0).Height
For Cell = 0 To cobacoba.dgv2.ColumnCount - 1
Dim CellValue As String = cobacoba.dgv2.Rows(Row).Cells(Cell).Value.ToString()
Dim CellWidth = cobacoba.dgv2.Rows(Row).Cells(Cell).Size.Width + 50
e.Graphics.DrawString(CellValue, f, br, CellLeftPos + offset, CellTopPos + offset)
e.Graphics.DrawRectangle(Pens.Black, CellLeftPos, CellTopPos, CellWidth, CellHeight)
CellLeftPos += CellWidth
Next
CellTopPos += cobacoba.dgv2.Rows(Row).Cells(0).Size.Height
If CellTopPos > e.MarginBounds.Bottom - cobacoba.dgv2.Rows(Row).Cells(0).Size.Height Then
e.HasMorePages = True
LastRow = Row + 1
Exit Sub
End If
Next
End Using
End Using
but the result is
what should I do?