I am trying to display a DataGrid
on my mobile application after reading a CSV file and processing it. Here is what I have so far:
private void btOpenFile_Click(object sender, EventArgs e)
{
try
{
// Process all data into an array of Object
// this.records array contains objects of type MyRecord
// Create datatable and define columns
DataTable dt = new DataTable("myDt");
dt.Columns.Add( new DataColumn("String A",typeof(string)));
dt.Columns.Add( new DataColumn("Int 1", typeof(int)));
// Loop through and create rows
foreach(MyRecord record in records) {
DataRow row = dt.NewRow();
row[0] = record.stringA;
row[1] = record.int1;
dt.Rows.Add(row);
}
// Create dataset and assign it to the datasource..
DataSet ds = new DataSet("myDs");
ds.Tables.Add(dt);
dataGrid.DataSource = ds;
dataGrid.Refresh();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message,"Error");
}
}
All I get is a blank data grid component when running my application. Can somebody point out my mistake? or how to do this correctly?
Try without DataSet dataGrid.DataSource = dt;