S
Soul
Hi,
I have a DataGrid which works. But if I load a new table to the DataGrid, it
will still show those old data I load earlier.
private void loadTableA()
{
if ( openFileDialog.ShowDialog() == DialogResult.OK )
{
this.dataGrid.SetDataBinding(null, null);
try
{
CurrentProject.FileReader fileReader = new
CurrentProject.FileReader();
try // Remove table is already exist in dataSet
{
dataSet.Tables.Remove( "tableA" );
}
catch ( System.ArgumentException )
{
// do nothing
}
dataSet.Tables.Add( fileReader.LoadData( openFileDialog.FileName,
"tableA" ) );
this.dataGrid.SetDataBinding( dataSet, "tableA" );
this.dataGrid.DataSource = dataSet.Tables["tableA"];
this.currencyManager = (CurrencyManager)
this.BindingContext[dataSet.Tables["tableA"]];
}
catch (System.ArgumentOutOfRangeException)
{
MessageBox.Show("Some Message", "Some Caption",
MessageBoxButtons.OK, MessageBoxIcon.Error );
}
}
}
Anyone know where did I do wrong?
Thank you.
I have a DataGrid which works. But if I load a new table to the DataGrid, it
will still show those old data I load earlier.
private void loadTableA()
{
if ( openFileDialog.ShowDialog() == DialogResult.OK )
{
this.dataGrid.SetDataBinding(null, null);
try
{
CurrentProject.FileReader fileReader = new
CurrentProject.FileReader();
try // Remove table is already exist in dataSet
{
dataSet.Tables.Remove( "tableA" );
}
catch ( System.ArgumentException )
{
// do nothing
}
dataSet.Tables.Add( fileReader.LoadData( openFileDialog.FileName,
"tableA" ) );
this.dataGrid.SetDataBinding( dataSet, "tableA" );
this.dataGrid.DataSource = dataSet.Tables["tableA"];
this.currencyManager = (CurrencyManager)
this.BindingContext[dataSet.Tables["tableA"]];
}
catch (System.ArgumentOutOfRangeException)
{
MessageBox.Show("Some Message", "Some Caption",
MessageBoxButtons.OK, MessageBoxIcon.Error );
}
}
}
Anyone know where did I do wrong?
Thank you.