Solved

DataGridView - Edited Cell does not Update when Reloading Data

Posted on 2008-11-01
5
1,059 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:mecdesign
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:needo_jee
ID: 22857820
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
0
 
LVL 8

Expert Comment

by:jorgesv13
ID: 22857823
If the DataGridView is bound to a BindingSource, you should also call the EndEdit method of the BindingSource:
BindingSource1.EndEdit()
0
 

Author Comment

by:mecdesign
ID: 22860348
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?
0
 
LVL 8

Accepted Solution

by:
jorgesv13 earned 500 total points
ID: 22867521
You can always save the CurrentCell to variable, then set  the DataGridView's CurrentCell to null, and then set it back to your current cell variable.
This will take the focus away from the cell, and then set it back to it, so the info will be saved anyway.
however, I normally accomplish this with calling to the EndEdit method of the BindingSource. Maybe you should add a BindingSource, so things run better.
0
 

Author Closing Comment

by:mecdesign
ID: 31512340
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.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question