Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All,

I have a Datagridview in Form1,and I am using Datatable as DataSource to Datagridview.

When User Edits Any Cell Value in particular Row, and Leaves that Row without Save Or Update, it should prompt a message saying that "You Want To Save Changes Or Not"

Any Idea or Suggestion would be appreciated.


Regards,
Pawan.
Posted
Updated 14-Oct-10 21:31pm
v3
Comments
Dalek Dave 15-Oct-10 3:32am    
Edited for Readability.
Henry Minute 15-Oct-10 8:54am    
Well done for finding a solution. I have up voted your question for the effort.
Pawan Kiran 25-Oct-10 0:02am    
I haven't Find the Solution Perfectly.
can some body help me on this please.

1 solution

You can use the DataGridView.OnSelectionChanged[^], DataGridView.OnRowEnter[^], DataGridView.OnRowLeave[^] events, to name but three of the many ways to do this.

Also think about the various Validating events.

Why not read the documentation to see if you can find better ways.
 
Share this answer
 
v2
Comments
Pawan Kiran 15-Oct-10 8:50am    
Hi Thanks to your post,

i considered CellLeaving also,
so I have used CellBeginEdit,CellEndEdit Events to solve my problem

But an Exception Prevents me to Solve my issue.

here is my code:

int originalvalue = 0;
private void dgridSLFElement_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
if (dgridSLFElement.Columns[dgridSLFElement.CurrentCell.ColumnIndex].Name.Equals("No of Clusters"))
{
originalvalue = string.IsNullOrEmpty(dgridSLFElement.CurrentCell.Value.ToString()) ? 0 : Convert.ToInt32(dgridSLFElement.CurrentCell.Value);
}
else
{
original_value = this.dgridSLFElement.CurrentCell.Value.ToString();
}
}
catch (Exception ex)
{
DataClass.LogError(ex);
}
}
private void dgridSLFElement_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
try
{
if (dgridSLFElement.Columns[dgridSLFElement.CurrentCell.ColumnIndex].Name.Equals("No of Clusters"))
{
if (this.dgridSLFElement.CurrentCell.Value.ToString() == originalvalue.ToString())
{
need_save = false;
}
else
{
need_save = true;
DialogResult dr = MessageBox.Show("Want To Update Changes Yes/No", "Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
saveSLFElement(this.dgridSLFElement.CurrentCell.RowIndex);
}
else
{ dgridSLFElement[this.dgridSLFElement.CurrentCell.ColumnIndex, this.dgridSLFElement.CurrentCell.RowIndex].Value = originalvalue.ToString();
}
}
}
}
catch (Exception ex)
{
DataClass.LogError(ex);
}
}

While Executing Code At this point
saveSLFElement(this.dgridSLFElement.CurrentCell.RowIndex)
i am getting an exception, saying that

Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.

Above Method Contains a PopupForm, GridViewBindMethod()..

Could you please Rectify my problem..

Thanks in advance.
Pawan.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900