假设我们有DataGridView dgv
和dgv.DataSource = dataTable
其中
dataTable = new DataTable()
。
问题是:我们通过dgv
访问的值(例如获取dgv[i,j]
)是否始终与dataTable
相同,反之亦然?
答案 0 :(得分:0)
我相信答案是肯定的。如果您查看Reflector中的DataGridViewCell.Value
属性并按照其曲折的路径,您将最终得到一些代码(在一堆噪声之后处理未绑定控件的情况)看起来像这样:
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);
所以在这里你可以看到访问Value
的{{1}}属性直接进入数据源。换句话说,在DataGridViewCell
中更新相应的行后,您可能会在DataGridView
中更新值,这是一个滞后的同步过程;一个人直接指向另一个。