Q: Load New Table to DataGrid

  • Thread starter Thread starter Soul
  • Start date Start date
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.
 
Hi Soul,

You can set some breakpoint to you application to watch the dataset object,
then
you can find what its internal structure is.

I think the simple way of updating your datagrid to display a new datatable
is
creating a new dataset and bind it to your datagrid.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Soul" <[email protected]>
| From: "Soul" <[email protected]>
| Subject: Q: Load New Table to DataGrid
| Date: Wed, 10 Sep 2003 03:41:11 +1000
| Lines: 51
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="utf-8"
| Content-Transfer-Encoding: 7bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: dsl-203-113-205-94.vic.netspace.net.au 203.113.205.94
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183525
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| 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.
| --
| Soul
|
|
|
|
 
Back
Top