How to execute event from another event?
I have a dategridview. It has UserDeletingRow event
private void dataGridVWTransactions_UserDeletingRow(
object sender,
DataGridViewRowCancelEventArgs e)
{
Dia开发者_Python百科logResult dr = MessageBox.Show(
"Do you want delete selected transaction?",
"Warning",
MessageBoxButtons.OKCancel);
if (dr == DialogResult.Cancel)
{
e.Cancel = true;
}
}
I want to call this Event from toolstripbutton control.
What must i Do?How can I do this?
I think you want to display a confirmation while deleting a row from Grid as well as User selects a row and press delete toolstrip button?
Instead of calling the event from Button, make the confirmation an another method and call it from two places.
Try this code
private bool ShowConfirm()
{
DialogResult dr = MessageBox.Show(
"Do you want delete selected transaction?",
"Warning",
MessageBoxButtons.OKCancel);
return dr == DialogResult.Cancel;
}
And in the GridView delete event
e.Cancel = ShowConfirm();
And in the Button
if(ShowConfirm())
{
//Do something
}
精彩评论