views:

14

answers:

1

Hi all,

I am searching about how to create variable number of columns in a DataGrid from the Ilist in MVVM way. The requirement I am working on is very big and also the number of rows and columns are not known But I did not find satisfactory answers

Is there some one that had to do the samething ?

If there is no way of generating such columns, I know I can do that by binding DataGrid to a DataSet. Then I have one more problem; if I am using DataSet, how do I display different UI in different cells based on some parameter?

Please help its very urgent requirement!!!!!!!!

A: 

Ok, I haven't tried this myself, but I think you should be able to pull this off by creating a dynamic object, and binding to a list of MyDynamicObject. WPF supports binding to dynamic objects (MSDN). Theoretically it could work like this:

public List<dynamic> MyDynamicList {get; set;}

dynamic obj = new MyDynamicObject();
obj.DisplayCode = "Test";
obj.SomeProperty = "hello world";
MyDynamicList.Add(obj);

You will need to create MyDynamicObject by implementing IDynamicMetaObjectProviderand DynamicMetaObject. More on this here.

Hope this will put you in the right direction...

Roel