简体   繁体   中英

c# datagridview not displaying data on second pass

Background :- Winforms app that imports data & performs some statistical analysis - stores the results in various data tables - displays the results in a datagridview & chart control. User can select the various statistical tests via a combobox & this updates the datagridview & chart with the appropriate data.

All works fine on the first pass (ie:- first time round). The user then has the option of starting afresh with the same, or new, data to include additional tests.

When the user does this with the same data, adding additional tests, the datagridview does not display the bound datatable information for any test reviewed previously.

When the user selects a new instance I am doing the following with the data tables / datagridview :-

            dataGridView1.DataSource = null;
            dataGridView1.Refresh();

            dataGridView1.Update();
            dataGridView1.DataSource = dataTable;

            dataTable.Clear();
            dataTable.Reset();

Interesting point is that the datagridview is only blank for the tests that have been reviewed. The other data appears as expected. If a new dataset is imported then all test rests are visible. If the user exits the application & re-launches it all test results are visible. It seems that the data is not visible in the datagridview for a data table that has been reviewed in a previous run.

Any ideas on how-to resolve this would be greatly appreciated.

Thanks.

IMHO, when you clear and reset DataTable, DataSource is also cleared. Try this:

DataTable newDataTable = dataTable;

dataGridView1.DataSource = null;
dataGridView1.Refresh();

dataGridView1.Update();
dataGridView1.DataSource = newDataTable;

dataTable.Clear();
dataTable.Reset();

I had the same problem with datagridview. In my case, the datagridview was on a panel. And datagridview didn't renew after updating data on it. Updating was done succesfully on database. But after updating it coulnt be got filled. I spent many time solving this problem. End of the day I have taken datagridview out of panel. And the problem was gone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM