I'm trying to rebind same grid to different datatables. The problem occurs when after sort by column gridview is rebound. During rebind it crashes bypassing catch..
Has anyone come across this (run this method , sort the gridview on any columns and run method again)
try
{
dt = new DataTable();
dt.Columns.Add(new DataColumn(string.Format("{0}{1}", "x", (new Random()).Next(1, 20))));
dt.Columns.Add(new DataColumn(string.Format("{0}{1}", "y", (new Random()).Next(43, 320))));
for (int i = 0; i < 15; i++)
{
DataRow dr = dt.NewRow();
dr[0] = (new Random()).Next(1, 90);
Thread.Sleep(100);
dr[1] = System.Convert.ToDouble("1." + (new Random()).Next(1, 203222));
dt.Rows.Add(dr);
}
dt.AcceptChanges();
this.dataGrid1.DataContext = dt;
this.dataGrid1.Rebind();
}
catch (Exception e)
{
string x = e.Message;
return;
}