Reputation: 252
I have a c# winforms app that allows users to select / print rows from a DataGridView
. I can't work out how to create a new line for each row. I have found a few answers for similar questions but none that work for me.
private void printDocument_PrintPage(object sender, PrintPageEventArgs ev)
{
Graphics graphic = ev.Graphics;
DataGridViewSelectedRowCollection rows = dataGridView1.SelectedRows;
foreach (DataGridViewRow row in rows)
{
DataRow myRow = (row.DataBoundItem as DataRowView).Row;
string myStr = string.Join( "|", myRow.ItemArray.Select( p => p.ToString( ) ).ToArray( ));
//myStr += "/n/r";
graphic.DrawString(myStr, new Font("Times New Roman", 10, FontStyle.Regular), Brushes.Black, 20, 225);
}
}
Everything I try just concatenates on to my string
Upvotes: 1
Views: 1835
Reputation: 28107
Adding a new line to a string is as simple as
myString += Environment.NewLine;
However, you will need to make sure that what you're using to display the string correctly renders new lines.
Upvotes: 1