Solved

Completing cell edit in DataGridView

Posted on 2010-11-14
4
707 Views
Last Modified: 2012-05-10
I'm using c# 4.0. I have a DataGridView on a form.

When the data changes (via CellValueChanged), a Save button is enabled that lets the user save, after which the button is disabled.

However, the user can type something into a cell but leave the cursor in the cell; effectively not committing the cell (CellValueChanged does not fire). Is there some way I can shift the mode from cell editing so that the value is committed when Save is clicked?
0
Comment
Question by:BlearyEye
  • 2
  • 2
4 Comments
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 34133722
You can try calling the EndEdit() method of the DataGridView upon leaving a cell.
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
    this.dataGridView1.EndEdit();
}

Open in new window

0
 
LVL 1

Accepted Solution

by:
BlearyEye earned 0 total points
ID: 34134365
That pointed me in the right direction. Just doing the EndEdit() resulted in losing the changes. I had to end the edit on the current row, then the data grid, then the binding source.

this.DataGridView1.CurrentRow.DataGridView.EndEdit();
this.DataGridView1.EndEdit();
bindingSource1.EndEdit();
taDevices.Update(tblDevices1.devices);

Open in new window


See disucssion at http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/f9b92a39-2c7d-4c33-b89d-8d58e391eb6a/
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34135849
Cool, glad you found an answer  :)
0
 
LVL 1

Author Closing Comment

by:BlearyEye
ID: 34182351
It pointed me in the right direction but needed more
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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

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

21 Experts available now in Live!

Get 1:1 Help Now