所以我有这个代码块来打印DataGridview行的集合。我想在一条单独的行中打印每一行,但它们都打印在同一行中。任何的想法?
foreach (DataGridViewRow row in rows)
{
DataRow myRow = (row.DataBoundItem as DataRowView).Row;
string myStr = string.Join("|", myRow.ItemArray.Select(p => p.ToString()).ToArray());
myStr += Environment.NewLine;
graphics.DrawString(myStr, new Font("Courier New", 12), new SolidBrush(Color.Black), startX, startY + Offset);
}
答案 0 :(得分:1)
您没有递增startY
坐标。
添加
startY = startY + 20;
前
graphics.DrawString(...)
如果您出于某种原因想要为每一行创建一个大字符串,请按以下方式进行:
string myStr = string.Empty;
foreach (DataGridViewRow row in rows)
{
DataRow myRow = (row.DataBoundItem as DataRowView).Row;
string myStr = string.Join("|", myRow.ItemArray.Select(p => p.ToString()).ToArray());
myStr += "\r\n";
}
graphics.DrawString(myStr, new Font("Courier New", 12), new SolidBrush(Color.Black), startX, startY + Offset);