string str = ""; int row = dataGridView1.Rows.Count; int cell = dataGridView1.Rows[1].Cells.Count; for (int i = 0; i < row; i++) { for (int j = 0; j < cell; j++) { if (dataGridView1.Rows[i].Cells[j].Value == null) { //return directly //return; //or set a value for the empty data dataGridView1.Rows[i].Cells[j].Value = ""; } str += dataGridView1.Rows[i].Cells[j].Value.ToString() + ","; } } write.WriteLine(str); string str2 = ""; int row2 = dataGridView2.Rows.Count; int cell2 = dataGridView2.Rows[1].Cells.Count; for (int i = 0; i < row2; i++) { for (int j = 0; j < cell2; j++) { if (dataGridView2.Rows[i].Cells[j].Value == null) { //return directly //return; //or set a value for the empty data dataGridView2.Rows[i].Cells[j].Value = ""; } str2 += dataGridView2.Rows[i].Cells[j].Value.ToString() + ","; } } write.WriteLine(str2);
foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewCell cell in row.Cells) { cell.Value = read.ReadLine(); } }
DataSource
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)