You have a read() in the while loop which crates problems for you when you do readline()
Instead of areadr.read().. I have changed to areader.peek().. Now the rows are getting read but the observablecollection and Dictionary is too complex for the datagrid to display the rows you need to work on that..
Instaed you could use a custom object collection as list..
the custom class
class PersonalInfo
{
public string ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
}
The modified code
void lFnGenerateData(StreamReader aReader)
{
try
{
bool lBlnIsColumns = true;
string[] lArrCols = null;
List<PersonalInfo> lstPersonalList = new List<PersonalInfo>();
dataGrid1.Columns.Clear();
while (aReader.Peek() > 0)
{
string lStrLine = aReader.ReadLine();
if (lStrLine == null)
break;
if (lStrLine.Trim() == "")
continue;
string[] lArrStrCells = null;
lArrStrCells = lStrLine.Split(';');
if (lArrStrCells == null)
continue;
if (lBlnIsColumns)
{
lArrCols = lArrStrCells;
foreach (string lStrCell in lArrStrCells)
{
DataGridTextColumn lDGCol = new DataGridTextColumn();
lDGCol.Header = lStrCell;
lDGCol.Binding = new System.Windows.Data.Binding(lStrCell);
dataGrid1.Columns.Add(lDGCol);
}
lBlnIsColumns = false;
continue;
}
if (lArrCols == null)
continue;
int lIntColID = 0;
PersonalInfo objPersonalInfo = new PersonalInfo();
objPersonalInfo.ID = lArrStrCells[0];
objPersonalInfo.FirstName = lArrStrCells[1];
objPersonalInfo.LastName = lArrStrCells[2];
objPersonalInfo.Address = lArrStrCells[3];
lstPersonalList.Add(objPersonalInfo);
}
aReader.Close();
dataGrid1.ItemsSource = lstPersonalList;
}
catch (Exception)
{
throw;
}
}