[英]Is DataGridView.DataSource synchronized with DataGridView UI?
假設我們有一個DataGridView dgv
和dgv.DataSource = dataTable
,其中
dataTable = new DataTable()
。
問題是:我們通過dgv
訪問的值dgv
像獲取dgv[i,j]
,始終是dataTable
,反之亦然?
我相信答案是肯定的。 如果您查看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);
因此,在這里您可以看到訪問DataGridViewCell
的Value
屬性將直接訪問數據源。 換句話說,這並不是一個滯后的同步過程,在DataTable
更新相應的行之后 ,您可能會在DataGridView
更新一個值; 一個只是指向另一個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.