C# MessageBox Confirm Yes No
In This C# Tutorial We Will See How To Use MessageBox To Confirm Delete With Yes And No Choice Using CSharp Programming Language.
-
-
Source Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Confirmation_Message : Form
{
public Confirmation_Message()
{
InitializeComponent();
}
private void Confirmation_Message_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("ID");
table.Columns.Add("First Name");
table.Columns.Add("Last Name");
table.Columns.Add("Age");
table.Rows.Add(1, "First A", "Last A", 10);
table.Rows.Add(2, "First B", "Last B", 20);
table.Rows.Add(3, "First C", "Last C", 30);
table.Rows.Add(4, "First D", "Last D", 40);
table.Rows.Add(5, "First E", "Last E", 50);
table.Rows.Add(6, "First F", "Last F", 60);
table.Rows.Add(7, "First G", "Last G", 70);
table.Rows.Add(8, "First H", "Last H", 80);
dataGridView1.DataSource = table;
}
private void BTN_REMOVE_Click(object sender, EventArgs e)
{
if(MessageBox.Show("Do You Want To Remove This Row","Remove Row",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
}
else
{
MessageBox.Show("Row Not Removed","Remove Row", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Confirmation_Message : Form
{
public Confirmation_Message()
{
InitializeComponent();
}
private void Confirmation_Message_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("ID");
table.Columns.Add("First Name");
table.Columns.Add("Last Name");
table.Columns.Add("Age");
table.Rows.Add(1, "First A", "Last A", 10);
table.Rows.Add(2, "First B", "Last B", 20);
table.Rows.Add(3, "First C", "Last C", 30);
table.Rows.Add(4, "First D", "Last D", 40);
table.Rows.Add(5, "First E", "Last E", 50);
table.Rows.Add(6, "First F", "Last F", 60);
table.Rows.Add(7, "First G", "Last G", 70);
table.Rows.Add(8, "First H", "Last H", 80);
dataGridView1.DataSource = table;
}
private void BTN_REMOVE_Click(object sender, EventArgs e)
{
if(MessageBox.Show("Do You Want To Remove This Row","Remove Row",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
}
else
{
MessageBox.Show("Row Not Removed","Remove Row", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}