开发者

Is DataGridView.DataSource synchronized with DataGridView UI?

assume we have a DataGridView dgv and dgv.DataSource = dataTable where

dataTable = new DataTable().

The question is: Is values we access through dgv like getting dgv开发者_如何学C[i,j] is always what we have in dataTable and vice versa ??


I believe the answer is yes. If you take a look at the DataGridViewCell.Value property in Reflector and follow its twisty path, you'll end up at some code that (after a bunch of noise to deal with the case of an unbound control) looks like this:

DataGridView.DataGridViewDataConnection dataConnection = dataGridView.DataConnection;
if (dataConnection == null)
{
    return null;
}
if (dataConnection.CurrencyManager.Count <= rowIndex)
{
    return this.Properties.GetObject(PropCellValue);
}
return dataConnection.GetValue(this.OwningColumn.BoundColumnIndex, this.ColumnIndex, rowIndex);

So here you can see that accessing the Value property of a DataGridViewCell is going straight to the data source. In other words it isn't some lagged synchronization process where you might have a value updated in the DataGridView after the corresponding row is updated in the DataTable; one just points straight to the other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜