Silverlight / WPF - Issue in CSV loading to Silverlight datagrid

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

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

 

 

 

    }

 

Thanks

Sreenath

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



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

Sreenath G V replied to Nikhil Mahajan on 17-May-11 12:52 AM
Hi...in http://pastebin.com/f56674dfb , 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 asp.net 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.