Here i have created sample using your code. In the message box i have shown the regno. So you need to write the code for delete the record by passing the regno.
Code
public Form1()
{
InitializeComponent();
BindGrid();
}
private void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("_regno", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
dgvstudentreg.DataSource = dt;
}
private void dgvstudentreg_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dgvstudentreg.CurrentCell.Value.ToString() == "Delete")
{
if (DialogResult.Yes == MessageBox.Show("\tAre you sure to Delete this Student Details?\t\t", "Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
string regNo = dgvstudentreg.CurrentRow.Cells["_regno"].Value.ToString();
// Write code for delete.
MessageBox.Show("Reg No: " + regNo);
}
}
BindGrid();
}
Screenshot
