I have a grid, when user adds new row and is editting it, i want to pop-up a Save/Discard current chanegs option message when he tries to shift focus to another row.
Problem is I am unable to get handle of new row, so that i could do if prevFocusHanlde == newRowHandle && editModeOn
I only have the -214... as newrow handle which is default, but after row validation, grid geenrates a new valid rowhandle for this new row. Where to record that ? Tried doing in RowUpdated, but it doesnt get called and by that time handle hasnt updated.
When an end-user starts to edit the new item row/card, the ColumnView.InitNewRow event is raised. You can handle this event to initialize particular fields within the new record. Once focus has moved to another row, the newly added row is added to the datasource and a blank new item row is displayed. The ValidateRow event is raised when a modified row is about to lose focus. Handle this event to specify whether row data is valid, and whether focus movement is allowed (you can use the ColumnView.IsNewItemRow method to determine whether the specified row is the New Item Row). Immediately after the row was added, its handle is equal to BaseView.DataRowCount - 1.
Related topics:
Whatever I understand from question you want to do something like below:
List<int> rowIndex = new List<int>();
private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
{
if (!rowIndex.Contains(e.RowIndex))
{
rowIndex.Add(e.RowIndex);
MessageBox.Show("Are you want to save changes?", "Save Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With