How to display objects with dynamic fields in wpf data grid?

Posted by Oliver Hanappi on Stack Overflow See other posts from Stack Overflow or by Oliver Hanappi
Published on 2010-03-24T21:55:43Z Indexed on 2010/03/24 22:33 UTC
Read the original article Hit count: 243

Filed under:
|
|
|

Hi!

I want to display and edit some objects in a WPF data grid and I'm looking for a good way to do so. All objects I want to display have the same fields, but every execution the fields of my objects can differ. Here is a piece of the interface to illustrate what I mean:

public interface IMyObject
{
    IEnumerable<string> GetFieldNames();
    IEnumerable<Type> GetFieldTypes();

    object GetField(string name);
    void SetField(string name, object value);
}

How can I generate a data grid which displays this kind of objects? I thought of XAML generation to define the columns, but I'm still facing the problem of accessing the fields. I think I could realize this with value converters, another option would be to dynamically create a type which exposes the dynamic fields with properties.

Are there any other ways and which should I favor? I'm keen on hearing your opinions.

Best Regards,
Oliver Hanappi

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#