نمایش هشدار قبل از حذف یک سطر از DataGridView
کد:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.Columns.Add("Column1", "Column1");
this.dataGridView1.Columns.Add("Column2", "Column2");
this.dataGridView1.Columns.Add("Column3", "Column3");
this.dataGridView1.Rows.Add(new object[] { "Ottima", "spoof", "20" });
this.dataGridView1.Rows.Add(new object[] { "Alireza Attacker", "4rm4n", "30" });
this.dataGridView1.Rows.Add(new object[] { "Nc 521", "Azad", "31" });
this.dataGridView1.Rows.Add(new object[] { "Pr0grammer", "Rezahck23", "30" });
}
private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
if (!e.Row.IsNewRow)
{
DialogResult res = MessageBox.Show("آیا از حذف این سطر مطمئن هستید؟", "Delete confirmation",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (res == DialogResult.No)
e.Cancel = true;
}
}
}
}