0
我已经创造了一个C#
DataGridView
。的DataGridView不刷新立即
private void SomeFunc()
{
DataGridView errorDataGrid = new System.Windows.Forms.DataGridView();
// Set properties for DataGrid View
// ..
// ..
// Add to the panel
somePanel.Controls.Add(this.errorDataGrid);
}
private void ShowOnGrid(string _message)
{
// create a new row and add a text to it
DataGridViewRow newRow = new DataGridViewRow();
newRow.CreateCells(this.errorDataGrid, _message);
// add this row to grid
this.errorDataGrid.Rows.Add(newRow);
// and scroll the bar to the newly added row, [currentRow = 0 initially]
this.errorDataGrid.FirstDisplayedScrollingRowIndex = currentRow++;
}
问题是数据(_message)在添加到网格后不会立即显示。相反,它突然显示,在节目结束
ShowOnGrid("My Message to show - 1")
ShowOnGrid("My Message to show - 2")
ShowOnGrid("My Message to show - 3")
ShowOnGrid("My Message to show - 4")
ShowOnGrid("My Message to show - 5")
ShowOnGrid("My Message to show - 6")
// End of program
所以所有的消息都显示在我的程序结束。 我错过了什么?或者在上面的程序中出现错误?
我提到以下,但找不到任何显著:
- DataGridView not refreshing and propagating data
- DataGridView not Refreshing
- Data not refreshing on datagridview C#
嘿,我通过在网格中添加一行后将其更正。我加了'dataGrid.Refresh()' – SimpleGuy