Link to home
Start Free TrialLog in
Avatar of mecdesign
mecdesign

asked on

DataGridView - Edited Cell does not Update when Reloading Data

I have an application that displays a DataGridView control.  Above it is a toolbar that lets you iterate through items in another control which loads the related data into the grid.

If I edit a cell (eg: click a checkbox cell) and then click my toolbar button to load new data for the next item, the value that appears in the cell I was previously editing is the one cell that does not update.  Although, if I click another cell after this problem occurs, the updated value *will* display.

This seems to be related to the cell being in edit mode and I am wondering if there is a way force the cell to stop editing.  Has anyone else run into this problem, and if so how did you solve this?

I have tried DaataGridView.EndEdit, but this alone did not seem to help.

Thanks.
Avatar of Munawar Hussain
Munawar Hussain
Flag of Pakistan image

hi, seems data is not updated into underlying datasource(is that a datatable?)
is so then before rebinding you can use aceptchanges on datatable..

also try

to update value to datasouce on cellLeave event.
most likely above would resolve the issue ..if not then please show the code if possible . then it would be easy to figureout the problem.

thanks
If the DataGridView is bound to a BindingSource, you should also call the EndEdit method of the BindingSource:
BindingSource1.EndEdit()
Avatar of mecdesign
mecdesign

ASKER

What I am doing is creating a  DataGridViewRow, calling Rows.CreateCells(DataGridView) and then DataGridView.Rows.Add(DataGridViewRow) to populate the grid.

One thing I have tried which works is to set the DataGridView.CurrentCell to null, although I end up losing the selected cell afterwards which is kind of inconvenient.

So at least it seems when the selected cell loses focus this issue goes away.  

However clicking a button in the toolbar alone does not seem to grab the focus away.  I have tried calling the Focus method (when a toolbar button is clicked) to see if that would help, but I did not have any luck with the controls that I tried setting focus to.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Jorge Sanchez
Jorge Sanchez
Flag of Ecuador image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In my case I cannot use the database as a binding source as it would interfere with a third party app, but I believe that would solve the problem if I could.