Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
Dynamic Columns using ExpandoObject
posted

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

Parents
  • 27093
    posted

    Hello,

     

    I have been looking into your description and usually the XamDataGrid does not support Ditionary data sources. Usually UnboundFields can be added without the need of corresponding properties like the with Field, but I am also not sure what would your DataRecords consist of if all your data is converted to Fields. Would you please describe in more details what your scenario is and by providing a small sample of the data you are going to use along with a description how do you want it to appear in the XamDataGrid.

     

    Looking forward to your reply.

     

    Sincerely,

    Petar Monov

    Developer Support Engineer

    Infragistics Bulgaria

    www.infragistics.com/support

     

Reply Children
No Data