Solved

DataGridView - Edited Cell does not Update when Reloading Data

Posted on 2008-11-01
5
1,061 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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