Click here to Skip to main content
14,869,378 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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; }


Updated 11-May-11 21:20pm
Dalek Dave 12-May-11 3:20am
Edited the code blocks.
humrahimcs1122 21-Feb-12 10:24am
thanks dear for help to resolve my problem.

You need to set the ItemsSource of the data grid to the underlying collection - in this case lArrObjclsGridLoadExcelData .
Sreenath Gv 12-May-11 2:47am
yeah that what is List<clsgridloadexceldata> lFnLoadCSVDataInGrid() returns and I am assigning to
dgrIncidents.ItemsSource = lFnLoadCSVDataInGrid();
Dalek Dave 12-May-11 3:20am
Good Call.
Abhinav S 12-May-11 4:44am
Sreenath Gv 12-May-11 4:25am
but not working...
Sreenath Gv 12-May-11 4:25am
still data in grid rows is blank...
Abhinav S 12-May-11 4:45am
Can you debug and check how many records are there in lArrObjclsGridLoadExcelData ?
Also how are you setting ItemsSoruce? Your xaml looks ok.
Sreenath Gv 12-May-11 4:49am
its 64 and after assigning to itemsource... even itemsource has got 64 records shown..
Any update on this guys...didnt get solution yet..
Mark Salsbery 16-May-11 13:46pm
Put a breakpoint on the lFnStopWait(); line. Examine dgrIncidents.ItemsSource. How many items are in the List? If more than zero, look at the items...are all the properties empty/null or do you see your values there?
Sreenath Gv 16-May-11 22:24pm
hi, item source have got all the cell details in csv null values. but even then rows are blank.
Mark Salsbery 17-May-11 3:10am
What does "lFnStopWait();" do?

To rule out XAML error, maybe try just a simple DataGrid:

<sdk:DataGrid name="dgrIncidents" autogeneratecolumns="True" />
Got the solution...

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:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900