Hi,
Is there a way to bind to IEnumerable<IDictionary<string, object>>.
Thanks
2 Answers, 1 is accepted
0
Julian Benkov
Telerik team
answered on 17 May 2012, 02:14 PM
Hello Maxim,
Thank you for writing.
This is not a supported functionality in RadGridView. You can bind to IEnumerable<T>, where T object must contain public properties to bind properly to RadGridView control. More information about binding you can find in our online documentation.
how Julian stated, wrap your IEnumerable<IDictionary<string, object>> with a Wrapper.
As I suppose, your IEnumerable are the rows and the pairs in your IDictionary are the "named" or mapped values for the Cells, where the Key is the Name, UniqueName or FieldName of the Column? In this case you have two ways:
a) Wrapper which creates a List with dynamic created objects (Key = Property) or
b) Wrapper of DataTable which easily? copies the pairs to the DataTable
c) Wrapper of IDataReader which get consumed by the Load method of a DataSet
where I mean the solution c) is simple to implement if you provide the related metadata for the "Fields" (your pair Keys). So you read directly from IEnumerable instance. Drawback is the lot of implementation of Methods from the interface. Read() will be connected to MoveNext() of IEnumerator<IDictionary<string, object>>, Values read from Current of the Enumerator and the access with FieldIndex of IDataReader goes via a metadata list of columnnames or columnmetadata collection (can be a List<DataColumn> or better KeyedCollection<DataColumn>). So also GetName and GetOrdinal of the interface can be supported.
As alternate to List<DataColumn> you can hold a none filled DataTable, where you only add the Columns for holding columns metadata.