I'm trying to create a datagrid with dynamic columns. The datasource is a Collection of ExpandoObject(s). They'all have the same properties.
I'm able to get this using the WPF native data grid as listed below
XAML
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Results}"/>
Code
IEnumerable<IDictionary<string, object>> rows = dataGrid1.ItemsSource.OfType<IDictionary<string, object>>();IEnumerable<string> columns = rows.SelectMany(d => d.Keys).Distinct(StringComparer.OrdinalIgnoreCase);foreach (string text in columns){ // now set up a column and binding for each property var column = new DataGridTextColumn { Header = text, Binding = new Binding(text) }; dataGrid1.Columns.Add(column);}
I'm trying to get the same behavior using XamDataGrid. I'm trying to dynamically add fields to a fieldlayout. This doesnt seem to work. Every ExpandoObject gets rendered as a Key Value Pair (I guess since it implements IDictionary<object,string>)
Is there a way I can get XamDataGrid to layout each property in the ExpandoObject as a field?
Thanks and appreciate your help
Hi Petar,
The new infragistics framework version got this issue as well. Do you have any options?
I wanted to do this exact same thing, I had to use a datatable instead. The code is almost as simple as when I was using an ExpandoObject.
I need to build colunn of xamDataGrid depends on data in xml. ExpandoObject is great solution for this issue (just declare Observablecollection<dinamic> and then create items of this collection and bind this collection to xamDataGrid), but this is now work with xamDataGrid. Can you suggest more detail solution for this issue without using ExpandoObject ?
I have exactly same requirement as mentioned above by Balakv. Would you be able to provide me sample code for Dynamic Columns using ExpandoObject or similar.
Thank you,
Shakti
Hi,
I am just checking if you require any furhter assistance on this matter.
Regards Petar.