簡體   English   中英

DataGridView.DataSource是否與DataGridView UI同步?

[英]Is DataGridView.DataSource synchronized with DataGridView UI?

假設我們有一個DataGridView dgvdgv.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);

因此,在這里您可以看到訪問DataGridViewCellValue屬性將直接訪問數據源。 換句話說,這並不是一個滯后的同步過程,在DataTable更新相應的行之后 ,您可能會在DataGridView更新一個值; 一個只是指向另一個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM