我有一個函數,導出我的Windows.Form應用程序DataGridView到CSV。 它工作正常,但問題是,我的DataGridView有兩行,每毫秒更新,但輸出到CSV沒有,它只是輸出的應用收盤後值...導出DataGridview到CSV每毫秒
public void writeCSV(DataGridView gridIn, string outputFile)
{
//test to see if the DataGridView has any rows
if (gridIn.RowCount > 0)
{
string value = "";
DataGridViewRow dr = new DataGridViewRow();
StreamWriter swOut = new StreamWriter(outputFile);
//write header rows to csv
for (int i = 0; i <= gridIn.Columns.Count - 1; i++)
{
if (i > 0)
{
swOut.Write(",");
}
swOut.Write(gridIn.Columns[i].HeaderText);
}
swOut.WriteLine();
//write DataGridView rows to csv
for (int j = 0; j <= gridIn.Rows.Count - 1; j++)
{
if (j > 0)
{
swOut.WriteLine();
}
dr = gridIn.Rows[j];
for (int i = 0; i <= gridIn.Columns.Count - 1; i++)
{
if (i > 0)
{
swOut.Write(",");
}
value = dr.Cells[i].Value.ToString();
//replace comma's with spaces
value = value.Replace(',', ' ');
//replace embedded newlines with spaces
value = value.Replace(Environment.NewLine, " ");
swOut.Write(value);
}
}
swOut.Close();
}
}
我調用的函數從SetDataGridView()函數我用它來更新DataGrids行每秒,但它仍然不會更新每個毫秒作爲DataGrid。
如何使DataGridView.Rows本身更新每毫秒更新CSV文件?
爲什麼要更新每毫秒數據網格視圖在第一位?您沒有更新頻率爲1000 Hz的屏幕,因此您只能看到部分更新。 – Guffa
我的意思是我更新每毫秒的行值... – ThisDude