I have a DataGridView in a form that will display the information
from
various DataTables in my DataSet. The user is provided a list of
tables and when they select a table name, the DataGridView displays
the appropriate DataTable. When a user changes some of the settings
in my program, I sometimes have to recreate some of the DataTables,
however, the DataGridView will still somehow display the original
DataTable even if the DataGridView had never displayed the original
table in the first place. Does anyone know why this would be
occurring?
I run the following code when I need to recreate a table:
//Remove existing table if there is one
if
(_dsDifferences.Tables.Contains(diffDataTable.Tabl eName) &&
_dsDifferences.Tables.CanRemove(diffDataTable.Tabl eName))
{
_dsDifferences.Tables.Remove(diffDataTable.TableNa me);
}
//Add the Differences Data Table to the Differences
Dataset
_dsDifferences.Tables.Add(diffDataTable);
When the user selects a table, I run the following:
dgDataDiffs.DataMember = "";
dgDataDiffs.DataSource = null;
dgDataDiffs.DataSource = _ds;
dgDataDiffs.DataMember = lstDataDiff.SelectedItem.ToString();
dgDataDiffs.AutoGenerateColumns = true;
The weird thing is, is that when I break into the code and look at my
dataset (_ds), the DataTable is the newly created datatable, so I
know
the table is getting recreated. The only solution I seem to be able
to come up with is to make a Copy of the Dataset and bind the copy to
the DataGridView, however, that is not feasible.
One thing I should add, is if I simply create a DataTable in a
dataset, then remove the table and create another DataTable with the
same name and then bind my DataSet/DataTable to a DataGridView that
was never bound to anything, the DataGridView shows the original
table. It seems like there is something I need to do after issuing
the Remove statement, but I don't know what it is.
Thanks,
Chris