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

Binding Data With Unknown Column Count

3 Answers 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 22 Jul 2009, 06:05 PM
I have data that is generated based on a myriad of user data from a database, and I've notice that most of the samples for binding data to the GridView require that you know the column names and count in order to create an object that represents a given collection of data. You have to create an object as a List<> or ObservableCollection.

Is there a way to bind data whosse makeup you have no knowledge of at runtime?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Daní
Top achievements
Rank 1
answered on 23 Jul 2009, 08:15 AM
Hi Andrew,

You may try to build dynamically DataTable with the incoming data. You can add so many DataColumns as "columns" you get.
0
Milan
Telerik team
answered on 23 Jul 2009, 11:41 AM
Hello Andrew,

You could try using the lightweight DataTable that Vladimir Enchev has implemented. You can find more information about it here: http://blogs.telerik.com/blogs/posts/09-04-23/lightweight_datatable_for_your_silverlight_applications.aspx

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Daní
Top achievements
Rank 1
answered on 23 Jul 2009, 01:26 PM
Oops, I forgot that DataSet, DataTable and so on are not present in Silverlight... I did a similar thing in a project a few months ago and I solved it using the System.Reflection.Emit namespace. That means creating a new type dynamically. In Visual Studio documentation you can find a very good, and easy (despite at first time it sounds tediuos) example.

Another issue you, maybe, will have to face is about templating the cells in each column, I suggest to use the XamlReader.Load() method to load dynamically the cell styles.

Hope this helps
Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Daní
Top achievements
Rank 1
Milan
Telerik team
Share this question
or