DataGridViewRowCollection 具有以下属性:
Count (public)
Gets the number of rows in the collection.
DataGridView (protected)
Gets the DataGridView that owns the collection.
Item (public)
Gets the DataGridViewRow at the specified index.
List (protected)
Gets an array of DataGridViewRow objects.
我的脑海中浮现出一个问题:我将如何使用这些 protected 成员?我假设它们占用文档空间是有原因的。
我认为可以使用的场景是派生我自己的类并告诉 DataGridView 使用该类。
但是,我不知道该怎么做(也许这很明显,但我只是没有看到它 - 这就是这里的答案)。
最佳答案
protected 项目只能从更派生的类访问。这意味着,如果您创建一个继承自 DataGridViewRowCollection
的 MyDataGridViewRowCollection
,那么您就可以访问 DataGridView
和 List
属性。
要创建一个继承自 DataGridViewRowCollection 的类,您只需执行以下操作:
public class MyDataGridViewRowCollection : DataGridViewRowCollection
{
public void MyMethod ()
{
}
}
关于c# - 框架类中记录的 protected 属性有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6778956/