簡體   English   中英

DataGridViewCellCollection 的屬性 Item 不存在

[英]The property Item of DataGridViewCellCollection does not exist

DataGridViewCellCollection 的文檔指出有一個屬性 Item,您可以為其使用索引或字符串名稱。 當我嘗試使用 DataGridViewCellCollection object 使用該屬性時,編譯器顯示此 object 不包含該屬性的錯誤,為什么?

該文檔有點誤導。 實際上它不是一個屬性Item ,而是一個索引器( 請參閱文檔),您可以使用它來訪問各個項目。 實際定義是

public System.Windows.Forms.DataGridViewCell this[int index] { get; set; }

如果你有一個DataGridViewCellCollection的實例(這里命名為_collection ),你可以使用

private DataGridViewCell GetCell(int index)
{
    return _collection[index]; // here we're accessing the item in the cell collection
}

訪問元素。

暫無
暫無

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

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