我想将我的数据写入DataGridView
文本文件。
以下代码写入数据,但格式不正确。
StreamWriter sW = new StreamWriter(dirLocationString);
string lines = "";
for (int row = 0; row< numRows1; row++){
for (int col = 0; col < 4; col++)
{
lines = lines + " " + dataGridView1.Rows[row].Cells[col].Value.ToString();
}
sW.WriteLine(lines);
}
sW.Close();
我希望输出格式如下:
AAAA, BBBB, CCCC, DDDD
但相反,它显示以下内容:
AAAA BBBB CCCC DDDD
AAAA BBBB CCCC DDDD AAAA BBBB CCCC DDDD
AAAA BBBB CCCC DDDD AAAA BBBB CCCC DDDD AAAA BBBB CCCC DDDD
and so on..