Silverlight / WPF - Issue in CSV loading to Silverlight datagrid

Asked By Sreenath G V on 16-May-11 09:00 AM


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: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}"/>




Back code


void lFnLoadDataInGrid()





      dgrIncidents.ItemsSource = lFnLoadCSVDataInGrid();



      catch (Exception)








    List<clsGridLoadExcelData> lFnLoadCSVDataInGrid()




      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;




        if (lStrLine == null)



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



        string[] lArrStrCells = null;


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


        if (lArrStrCells == null)



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



        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];








      return lArrObjclsGridLoadExcelData;


      catch (Exception ex)



      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; }








Nikhil Mahajan replied to Sreenath G V on 16-May-11 11:38 PM
hey just go through below will show you how to bind datagrid with datasources like (dataset,datatable)

sol : 2

and then I adapted some code from this excellent idea:

mashing it all together and eventually coming up with:

Sreenath G V replied to Nikhil Mahajan on 17-May-11 12:52 AM , example...what is csvreader...? is there any library for this..?
Nikhil Mahajan replied to Sreenath G V on 17-May-11 01:07 AM
CSV reader is for  reading and parseing a CSV file?

CSVReader - is a simple open source C# class library to read CSV data

go through this link......

Sreenath G V replied to Nikhil Mahajan on 17-May-11 01:38 AM
hi..but this csv reader class for normal applications and not silverlight as datatable and stuff wont be there in silverlight...i hope u have seen the csvreader class..
Nikhil Mahajan replied to Sreenath G V on 17-May-11 03:29 AM
If you have the source code, then it does not need to be Silverlight specific.