This is a migrated thread and some comments may be shown as answers.

Table with Dictionary List or ExpandoObject List

2 Answers 250 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Maicon
Top achievements
Rank 2
Maicon asked on 24 Jan 2012, 05:57 PM
Hello,

I'm trying to create a dynamic report, I used a example I found here in this forum, and it worked fine while I had a object list. Now I have a list of dictionary (IQueryable<Dictionary<string, object>>) that I create base on business rules. The problem is I can't create the columns properly, I tried to bind the columns with "=Item[\"name_of_column\"]" and even with tried to inherit the dictionary class, creating a function to do the "Item[]" action, but did not work. Same problem with ExpandoObject, I can't access as dictionary, and I can't access the properties directly.

Actually it would be simpler to work with a Dictionary, how do I access the values based on the keys? Other option I tried and did not work was to create a User Function to get the value, but I can't access the current row object or the current row index.

2 Answers, 1 is accepted

Sort by
0
Accepted
Elian
Telerik team
answered on 26 Jan 2012, 05:28 PM
Hello Maicon,

The dictionary can be treated as List<KeyValuePair<TKey, TValue>> because it implements IEnumerable<KeyValuePair<TKey, TValue>>. "Item" is the keyword for accessing unnamed items of lists, arrays, etc. 
So in this case the expressions you need to use are:
"=Fields.Item.Key" and "=Fields.Item.Value".

However if you have List<Dictionary<K, V>> this is another level of nesting. You cannot bind directly to the items inside the dictionary. You must first bind the Dictionary to a component that supports binding (Subreport, List, Table..) and then inside this component's context you can use the Dictionary as explained above.

Greetings,
Elian
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Habib
Top achievements
Rank 1
answered on 30 Jul 2012, 09:59 AM
Hi,

And can you tell me how can I proceed, if I have and object the contains a Dictionnary object.

Ex: I have an object called Entity, and Entity.Properties is a Dictionnary object. and Entity.Properties["Name"] will return "Toto";

Best Regards
Tags
General Discussions
Asked by
Maicon
Top achievements
Rank 2
Answers by
Elian
Telerik team
Habib
Top achievements
Rank 1
Share this question
or