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