将csv文件加载到Silverlight中的DataGrid中。 [英] Load a csv file into a DataGrid in Silverlight.

查看:84
本文介绍了将csv文件加载到Silverlight中的DataGrid中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何使用csv文件加载DataGrid?在Winforms中,通过dg.Rows.Add({object()})非常容易。 Silverlight DataGrid中不提供此方法。如果还有另一种显示此类数据的方法,我愿意接受建议。



这里的技巧我需要它是动态的。在没有先验知识的情况下打开任意列数的csv文件。



搜索 - 是的,我的尾巴没什么符合我的标准。



我的尝试:



Anyone know how to load a DataGrid with a csv file? In Winforms it was quite easy by means of dg.Rows.Add({object()}). This method is not available in the Silverlight DataGrid. If there is another approach to displaying this kind of data I am open to suggestions.

The trick here that I need it to be dynamic. Open any csv file of diff number of columns without prior knowledge.

Searching - yeah my tail off, nothing matches my criteria.

My attempt:

Dim ofd As New OpenFileDialog
     If ofd.ShowDialog Then
       If IO.File.Exists(ofd.File.FullName) Then
         Dim srsCol As New List(Of String())
         Using fs As IO.FileStream = ofd.File.OpenRead
           Using sr As New IO.StreamReader(fs)
             While Not sr.Peek = -1
               srsCol.Add((sr.ReadLine.Split(","c).ToArray))
             End While
           End Using
         End Using
         dgStaff.ItemsSource = srsCol
       End If
     End If

推荐答案

您在Google中搜索的内容如何?你搜索过它了吗?



无论如何,有一篇很棒的文章此处 [ ^ ]。



祝你好运。
What about your search in Google? Did you search on it, right?

Anyway, there is a great article here[^].

Best regards.


我解决了它并将其发布在CodePlex的讨论板上,因为解决方案涉及到使用这个扩展的DataGrid。



Bindable Datagrid
I solved it and posted it in the discussions board on CodePlex since the solution involves using this extended DataGrid.

Bindable Datagrid


这篇关于将csv文件加载到Silverlight中的DataGrid中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆