Solved

DataGridView - Edited Cell does not Update when Reloading Data

Posted on 2008-11-01
5
1,055 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now