views:

4726

answers:

3

I have an app that receives XML from a server. I want to bind the data to a data grid and it would be grate if the grid auto generated the columns. So far I have tried to this much in my code.

XAML page:

<data:DataGrid x:Name="Status" ItemsSource="{Binding}" AutoGenerateColumns="True">
</data:DataGrid>

Code behind for the page:

void Status_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    XElement recordSet = XElement.Load(e.Result);
    CamerasStatusTabDataGrid.ItemsSource = recordSet.Elements("Status");
}

XML from the server:

<StatusReport>
    <Status Description="Spilled Coffe on Server" Date="2/5/2009" />
    <Status Description="Mice in Copier" Date="4/3/2008" />
    <Status Description="Helped User Find Any Key" Date="6/2/2008" />
</StatusReport>

What I am looking to do is to have the status be a row in the grid with "Description" and "Date" being columns.

A: 

Please take a look on the following link.

It contains running code (on my environment) that creates a class with properties at runtime. The class is used to populate a generic IList<object> that can serve as source for the datagrid.

I didn't feel confortable posting the code here because 99.99999% of it is not mine.

The links takes you to the original post where you will find the Silverlight working code as a comment posted by me.

Klinger
This is a good tutorial. However, I'm looking for a way to bind the data dynamically since i may not know the names of all the columns.
JustSmith
+2  A: 
Peter McGrattan
It works. Not dynamic but it works!
JustSmith
A: 

Smith,

I had a similar requirement that you have mentioned. I have posted an article in code project on the solution. http://www.codeproject.com/KB/silverlight/SilverlightDGFromMDB.aspx

I hope this helps.

Thanks R. Arasu Elango

Arasu Elango