views:

1542

answers:

2

I'm having a go at moving one of our simpler apps to Silverlight (a bit of a learning exercise). I've quickly come unstuck as I can't figure out how to load (or bind maybe?) a csv file to a datagrid (i.e. so you can point the app at a local csv file and display it to the user). I do have boilerplate code to parse a csv file and return a datatable but I'm shocked to discover that Silverlight doesn't even support DataTable (wtf!).

Any ideas at all how to do this? How do people bind data to a datagrid anyhow?

I'm using Silverlight 3.0 included in VS2010.

A: 

Maybe this resource helps: Data Binding in Silverlight 3

Konamiman
+2  A: 

Christ finally got it working (might be a bit kludgy tho). So in the end I used the CSVReader (not my code, nicked from someone ages ago):

http://pastebin.com/f56674dfb

and then I adapted some code from this excellent idea:

http://blog.bodurov.com/blog/Post.aspx?postID=27

mashing it all together and eventually coming up with:

http://pastebin.com/fb64198e

Thankyouverymuch!

In the end I adapted the CSV reader to use this excelent datatable class

Calanus
As a suggestion, consider moving that CVS reader code out of your code-behind. It really doesn't belong there. It should be its own class for several reasons.
Brian Genisio
I found this more simple for dynamically creating the columns http://slbindabledatagrid.codeplex.com/ compared to Vladimir Bodurov's example you gave.
Jason Rowe
Yes you are right - in the end I would use the slbindabledatagrid rather than the Bodurov solution
Calanus