The following method is used by me to convert the cells in a datagrid view into a single string and print the string in the console when button is licked!
private void button3_Click(object sender, EventArgs e)
{
String file = "";
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
file = file + dataGridView1.Rows[i].Cells[j].Value.ToString();
}
}
Console.WriteLine(file);
}
But i get the following error "An unhandled exception of type 'System.NullReferenceException' occured' with the code line dataGridView1.Rows[i].Cells[j].Value.ToString(); highlighted! How can I correct this issue?