Printing a C# datagridview and so far I have been able to print out the column names but I can't get the information underneath to show up. I'm not using anysource for the data just letting the user input it into a grid like format.
for
(int i = 0; i < dgv.Columns.Count; ++i){
string caption = dgv.Columns[i].HeaderText;w = dgv.Columns[i].Width;
if (xPos + w > x + dgv.Width)w = x + dgv.Width - xPos;
if (xPos < x + dgv.Width)mp.DrawString(caption, printFont, _Brush, xPos, yPos, w, h);
if (i == 0) // draw horizontal line below headermp.DrawLines(_Pen, x, yPos + h, x + dgv.Width, yPos + h);
xPos += w;
for (int j = 0; j < dgv.Rows.Count; ++j){
foreach (DataGridViewColumn dc in dgv.Columns){
string value = dc.DataPropertyName.ToString();}
}
}
DavePosted Jan 29, 2008, 6:57 PM
If you are happy to use an existing class, there is a datagridviewprinter class here - http://www.codeproject.com/KB/printing/datagridviewprinter.aspx (it has been improved upon here - http://www.nomorepasting.com/getpaste.php?pasteid=8281 ). The first link provides instructions as to how you use it.
I found this to be an excellent class and recently used it on a project. It worked beautifully.