how to avoid a leave event after it is called
-
hello, im looking for a solution with a slight problem that im sure it is possible, but i cant find anything about it on the web. In my code, im calling a leave event out of a control that check's if the control has made any changes (txtBox, combo Box...) raising a question telling the user that changes weren't saved. if the user click's on Cancel button, i want him to stay in the control and not actually leave like he initially did. How can i do it ? Thanks
private void TabControlChars_Leave(object sender, EventArgs e)
{
DataTable charChanges = null;if (charsTypeDT != null) { charChanges = charsTypeDT.GetChanges(); } else if (charsDT != null) { charChanges = charsDT.GetChanges(); } if (charChanges != null) { DialogResult result; result = MessageBox.Show("Changes were made without saving !!\\n" + "All Changes will be lost ...", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.Cancel) { ??? } } }
-
hello, im looking for a solution with a slight problem that im sure it is possible, but i cant find anything about it on the web. In my code, im calling a leave event out of a control that check's if the control has made any changes (txtBox, combo Box...) raising a question telling the user that changes weren't saved. if the user click's on Cancel button, i want him to stay in the control and not actually leave like he initially did. How can i do it ? Thanks
private void TabControlChars_Leave(object sender, EventArgs e)
{
DataTable charChanges = null;if (charsTypeDT != null) { charChanges = charsTypeDT.GetChanges(); } else if (charsDT != null) { charChanges = charsDT.GetChanges(); } if (charChanges != null) { DialogResult result; result = MessageBox.Show("Changes were made without saving !!\\n" + "All Changes will be lost ...", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.Cancel) { ??? } } }
Try setting focus back to the textbox. You can also place the code in the Validating event and then use Cancel property of the CancelEventArgs there to remain in the textbox.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
hello, im looking for a solution with a slight problem that im sure it is possible, but i cant find anything about it on the web. In my code, im calling a leave event out of a control that check's if the control has made any changes (txtBox, combo Box...) raising a question telling the user that changes weren't saved. if the user click's on Cancel button, i want him to stay in the control and not actually leave like he initially did. How can i do it ? Thanks
private void TabControlChars_Leave(object sender, EventArgs e)
{
DataTable charChanges = null;if (charsTypeDT != null) { charChanges = charsTypeDT.GetChanges(); } else if (charsDT != null) { charChanges = charsDT.GetChanges(); } if (charChanges != null) { DialogResult result; result = MessageBox.Show("Changes were made without saving !!\\n" + "All Changes will be lost ...", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.Cancel) { ??? } } }
-
Sorry, but i didnt get you.. the message Box is created inside the Leave event so how can i put the event in the cancel button click event ?