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

[Solved] List<object> insted of List<Type> in ItemsSource binding?

2 Answers 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paulo
Top achievements
Rank 1
Paulo asked on 14 Oct 2009, 05:28 PM

Hello.

I'm trying to use the GridView to automatically display the fields of my object. so, lets start with that object:

public class Item     
{     
    public Item() { }     
    public int Id { getset; }     
    public string Name { getset; }     
    public DateTime Creation { getset; }     

Then I generate some dummy data, to test the grid:

private List<Item> GenerateFakeData()  
{  
    List<Item> list = new List<Item>();  
    for (int i = 0; i < 10; i++)  
    {  
        list.Add(new Item { Id = i, Name = "Name (" + i + ")" });  
    }  
    return list;  
}  
 

Finally i bind my list to the Grid:

  this.radGridViewDataBinding.ItemsSource = GenerateFakeData();

This works well. The problem is if I change the DataType of the Item to object (in my Generator) as follow :

private List<object> GenerateFakeData()   
{  
    List<object> list = new List<object>();  
    for (int i = 0; i < 10; i++)  
    {  
        list.Add(new Item { Id = i, Name = "Name (" + i + ")" });  
    }  
    return list;  
}  
 

This way it does'nt work....

Since I'm generating item dataType in runtume (by reflection), I cannot instantiate the Generic type of the List to any kind of object.
Is this a bug, or a feature?
How can I workaround this problem?

Thanks in advance
Paulo Paiva

2 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 15 Oct 2009, 06:33 AM
Hi Paulo,

Currently this is a limitation which we will eliminate in a future release but for now you could try to use the LightWeight DataTable class. It allows you to bind RadGridView to dynamically generated data and add/remove columns at runtime.

Hope this helps.

Greetings,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Paulo
Top achievements
Rank 1
answered on 15 Oct 2009, 09:43 AM
Hi,

Thanks for your response.
I will use the DataTable as you suggest. I think it will resolve my problems.

Thanks again.
Paulo
Tags
GridView
Asked by
Paulo
Top achievements
Rank 1
Answers by
Milan
Telerik team
Paulo
Top achievements
Rank 1
Share this question
or