CSV加载到Silverlight DataGrid中的问题 [英] Issue in CSV loading to Silverlight datagrid

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

问题描述


我现在对这个问题一无所知.加载整个数据后,所有行在网格中均显示为空白.这是我的代码.
请帮助我在哪里做错了…网格中填充的所有行都显示为空白..
网格定义…

Hi,
I am now blank with this issue. After loading the whole data, all the rows are showing blank in grid. Here is my code..
Please help out where I am doing mistake…all the rows been filled in grid are showing blank..
Grid definition…

<sdk:DataGrid  Name="dgrIncidents"   AutoGenerateColumns="False"  HeadersVisibility="All"

                                                RowBackground="Cornsilk" AlternatingRowBackground="LemonChiffon"

                                                 IsReadOnly="True" CanUserResizeColumns="True" GridLinesVisibility="All">
                            <sdk:DataGrid.Columns>
                                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Reported Date" Binding="{Binding Reported_Date}"/>
                                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Incident ID" Binding="{Binding Incident_ID}"/>
                                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Closed Date" Binding="{Binding Closed_Date}"/>
                                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Last Resolved Date" Binding="{Binding Last_Resolved_Date}"/>
                                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Assigned Group" Binding="{Binding Assigned_Group}"/>
                                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Assignee" Binding="{Binding Assignee}"/>
                                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Status" Binding="{Binding Status}"/>
                                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Summary" Binding="{Binding Summary}"/>
                            </sdk:DataGrid.Columns>
                        </sdk:DataGrid>


返回代码


Back code

void lFnLoadDataInGrid()
        {
            try
            {
                lFnStartWait();
                dgrIncidents.ItemsSource = lFnLoadCSVDataInGrid();
                lFnStopWait();
            }
            catch (Exception)
            {

                throw;
            }
        }


        List<clsGridLoadExcelData> lFnLoadCSVDataInGrid()
        {
            try
            {
                if (Prp_Opendialogue.File == null)
                {
                    lFnShowPopupErr("Please select CSV file");
                    return null;
                }

                List<clsGridLoadExcelData> lArrObjclsGridLoadExcelData = new List<clsGridLoadExcelData>();

                StreamReader lObjStreamReader = new StreamReader(Prp_Opendialogue.File.OpenRead());

                bool lBlnIsColumnRow = true;

                while (lObjStreamReader.Read() != null)
                {
                    string lStrLine = lObjStreamReader.ReadLine();

                    if (lBlnIsColumnRow)
                    {
                        lBlnIsColumnRow = false;
                        continue;
                    }

                    if (lStrLine == null)
                        break;

                    if (lStrLine.Trim() == "")
                        continue;

                    string[] lArrStrCells = null;

                    lArrStrCells = lStrLine.Split(",".ToCharArray());

                    if (lArrStrCells == null)
                        continue;

                    if (!(lArrStrCells.Length == 8))
                        continue;

                    clsGridLoadExcelData lObjclsGridLoadExcelData = new clsGridLoadExcelData();

                    lObjclsGridLoadExcelData.Reported_Date = lArrStrCells[0];
                    lObjclsGridLoadExcelData.Incident_ID = lArrStrCells[1];
                    lObjclsGridLoadExcelData.Closed_Date = lArrStrCells[2];
                    lObjclsGridLoadExcelData.Last_Resolved_Date = lArrStrCells[3];
                    lObjclsGridLoadExcelData.Assigned_Group = lArrStrCells[4];
                    lObjclsGridLoadExcelData.Assignee = lArrStrCells[5];
                    lObjclsGridLoadExcelData.Status = lArrStrCells[6];
                    lObjclsGridLoadExcelData.Summary = lArrStrCells[7];

                    lArrObjclsGridLoadExcelData.Add(lObjclsGridLoadExcelData);
                }

                lObjStreamReader.Close();
                lObjStreamReader.Dispose();

                return lArrObjclsGridLoadExcelData;
            }
            catch (Exception ex)
            {
                lFnShowPopupErr(ex.Message.ToString());
                return null;
            }
        }

   class clsGridLoadExcelData
        {


            public string Reported_Date { get; set; }
            public string Incident_ID { get; set; }
            public string Closed_Date { get; set; }
            public string Last_Resolved_Date { get; set; }
            public string Assigned_Group { get; set; }
            public string Assignee { get; set; }
            public string Status { get; set; }
            public string Summary { get; set; }



        }


谢谢
Sreenath


Thanks
Sreenath

推荐答案

您需要将数据网格的ItemsSource设置为基础集合-在本例中为 lArrObjclsGridLoadExcelData .
You need to set the ItemsSource of the data grid to the underlying collection - in this case lArrObjclsGridLoadExcelData .


对此家伙的任何更新...尚未获得解决方案..
Any update on this guys...didnt get solution yet..


得到解决方案...

嘿,只需通过下面的链接即可....它将向您展示如何将datagrid与数据源(如(dataset,datatable))进行绑定

http://slbindabledatagrid.codeplex.com/


溶胶:2

http://pastebin.com/f56674dfb
然后我从这个好主意改编了一些代码:
http://blog.bodurov.com/blog/Post.aspx?postID=27
将它们融合在一起,最终提出:
http://pastebin.com/fb64198e
Got the solution...

hey just go through below link....it will show you how to bind datagrid with datasources like (dataset,datatable)

http://slbindabledatagrid.codeplex.com/


sol : 2

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


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

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