Solved

DataGridView - Edited Cell does not Update when Reloading Data

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
No Data for DropDown List 2 28
Can I command line build a C# application? 6 40
linq, c# 8 22
JQuery Detecting page post back 6 6
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

791 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