私の目標は、に似たカスタム構造にバインドして、構造に関する情報を「検出」DataTableできるようにすることでした。DataGrid
簡単な答えは、次のインターフェイスを実装することです。
IList
IEnumerable
ITypedList
から継承するCustomTypeDescriptor(または実装するICustomTypeDescriptor)だけでなく
この質問CustomTypeDescriptorは、最も困難なものを扱うのに大いに役立ちました。
私の列挙オブジェクトは、メインテーブルへの参照を格納する単純なオブジェクトであり、特定の行と列の値を尋ねることができました。
public AgilityTableRow(AgilityTableBase table, int rowIndex)
{
_table = table;
_rowIndex = rowIndex;
}
public object this[int columnIndex]
{
get
{
return _table[columnIndex, _rowIndex];
}
}
public object this[string columnName]
{
get
{
return _table[_table.GetFieldIndex(columnName), _rowIndex];
}
}
注:このクラスは実装する必要がICustomTypeDescriptorあり、プロパティを取得するために呼び出しをテーブルに転送するだけです。
public PropertyDescriptorCollection GetProperties()
{
return _table.GetProperties();
}