Hi,
I have designed form in windows application using c#.i had used datagrid .i want how to print the datagrid display records.
Datagrig record printout
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
paiha paiga45 pointsPosted Oct 29, 2008, 10:55 PM EDT
print :
private void DrawGridBody(Graphics g, ref int columnPosition, ref int rowPosition)
{
// loop through each row and draw the data to the graphics
// surface.
foreach (DataRow dr in scheduleDataSet.Tables[0].Rows)
{
columnPosition = 0;
// draw a line to separate the rows
g.DrawLine(Pens.Black, new Point(0, rowPosition), new Point(this.Width, rowPosition));
// loop through each column in the row, and
// draw the individual data item
foreach (DataGridViewColumn dc in gridExercise.Columns)
{
// if its a picture, draw a bitmap
if (dc.DataPropertyName == "Picture")
{
if (dr[dc.DataPropertyName].ToString().Length != 0)
{
if (CustomImageCell.Images.ContainsKey(dr[dc.DataPropertyName].ToString()))
{
g.DrawImage(CustomImageCell.Images[dr[dc.DataPropertyName].ToString()],
new Point(columnPosition, rowPosition));
}
}
}
else if (dc.ValueType == typeof(bool))
{
// draw a check box in the column
g.DrawRectangle(Pens.Black, new Rectangle(columnPosition, rowPosition + 20, 10, 10));
}
else
{
// just draw string in the column
string text = dr[dc.DataPropertyName].ToString();
if (dc.DefaultCellStyle.Font != null)
g.DrawString(text, dc.DefaultCellStyle.Font, Brushes.Black,
(float)columnPosition, (float)rowPosition + 20f);
else
g.DrawString(text, this.Font, Brushes.Black, (float)columnPosition, (float)rowPosition + 20f);
}
// go to the next column position
columnPosition += dc.Width + 5;
}
// go to the next row position
rowPosition = rowPosition + 65;
}
}
Enjoy...