DatagridView Shows Removed Table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    DatagridView Shows Removed Table

    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.Contain s(diffDataTable .TableName) &&
    _dsDifferences. Tables.CanRemov e(diffDataTable .TableName))
    {


    _dsDifferences. Tables.Remove(d iffDataTable.Ta bleName);
    }


    //Add the Differences Data Table to the Differences
    Dataset
    _dsDifferences. Tables.Add(diff DataTable);


    When the user selects a table, I run the following:


    dgDataDiffs.Dat aMember = "";
    dgDataDiffs.Dat aSource = null;
    dgDataDiffs.Dat aSource = _ds;
    dgDataDiffs.Dat aMember = lstDataDiff.Sel ectedItem.ToStr ing();
    dgDataDiffs.Aut oGenerateColumn s = 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

Working...