メッセージボックスを使用して、ユーザーがグリッドビューから行を削除するかどうかを確認しますが、どのような回答をしてもフォームを閉じてform1に戻ります
これは、viewTransactions フォームが読み込まれる場所です。このコードは Form1 にあります。
private void btnViewTrans_Click(object sender, EventArgs e)
{
viewTransactions = new View_Transactions(newList);
if (viewTransactions.ShowDialog() == DialogResult.OK)
{
newList.Equals(viewTransactions.getList());
}
}
これは、viewTransaction フォームで messageBox が表示される場所です。
///////////////////////////////
//Remove an item from the list
private void button3_Click(object sender, EventArgs e)
{
DialogResult result = new DialogResult();
result = MessageBox.Show("Are you sure you want to delete this element?", "Confirmation", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
{
tmpList.remove(item.Index);//remove item from tmpList used to update the passed in list
dataGridView1.Rows.RemoveAt(item.Index);//remove the item from the dataGrid
}
}
}
メッセージボックスを使用して警告を表示するまで、コードに問題はありませんでした。DialogResult が他の ShowDialog に渡されていると思います。それが私のフォームを閉じている理由です。