So I am just joining the WPF club after dabbling in Winforms for a couple of years. I am definiately enjoing the databinding in WPF, but I am having trouble with the DataGrid.
I have a highly-customized data structure that stores results from a SQL query, which I would like to continue to use in WPF. I have seen examples of binding to lists of objects, but not for anything dynamic like a SQL query.
Is there some interface that I can make my data structure implement so the DataGrid can get the necessary information such as the row & column count, headers, and the data?
My goal was to bind to my custom structure similar to a
DataTable, allowing theDataGridto “discover” information about my structure.The short answer is to implement the following interfaces:
IListIEnumerableITypedListAs well as inheriting from
CustomTypeDescriptor(or implementingICustomTypeDescriptor)This Question helped a lot in dealing with the
CustomTypeDescriptorstuff which was the most challenging.My enumeration object was simple an object that stored a reference back to the main table so it could ask what the value was at a specific row and column.
Note: this class needs to implement
ICustomTypeDescriptorand can simply forward the call to the table to get the properties: