Datagridview confused on row count

  • Thread starter Thread starter Uhane
  • Start date Start date
U

Uhane

I have a windows form with the datagridview that displays data from a
single table. The underlying data can be updated/deleted from another
component.

In our case, we raise an event when any underlying changes happen. We
then have been trying to refresh our grid without much luck.

We use:
this.DataSet.Offers.Clear();
this.offersTableAdapter.Fill(this.DataSet.Offers);
this.offersBindingSource.ResetBindings(false);
this.offersDataGridView.Refresh();

We have tried multiple variations but the underlying data is fairly
small. Unfortunately, if a row is deleted often the grid will then
think that two rows have been deleted. If the grid is refreshed a
second time, then the correct rows are shown.

Can someone suggest the proper way to go about this or point out the
error in our refresh syntax?

Thanks
 
I have a windows form with the datagridview that displays data from a
single table. The underlying data can be updated/deleted from another
component.

In our case, we raise an event when any underlying changes happen. We
then have been trying to refresh our grid without much luck.

We use:
this.DataSet.Offers.Clear();
this.offersTableAdapter.Fill(this.DataSet.Offers);
this.offersBindingSource.ResetBindings(false);
this.offersDataGridView.Refresh();

We have tried multiple variations but the underlying data is fairly
small. Unfortunately, if a row is deleted often the grid will then
think that two rows have been deleted. If the grid is refreshed a
second time, then the correct rows are shown.

Can someone suggest the proper way to go about this or point out the
error in our refresh syntax?

Thanks

We did in the end discover our error. We were checking in the
rowdeleting event to make sure the user wished to delete the row.
Unfortunately, we just included an else structure that went ahead with
the delete and ultimately updated the grid while still in this event
call. Because the grid still believed that it was in the middle of an
edit, it confused the row count even though it wasn't actually doing
to the deletion.

In the end, by moving our deletion routine as well as our refresh code
to the rowdeleted event, everything works as expected.

We also decided to set the grid's datasource to null, refresh the
dataset and then set the datasource back to the desired table for the
grid.

Hope this helps someone else with the same problem.
 
Back
Top