Click here to Skip to main content
14,878,669 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to delete selected row for data grid view in c# 2010 windows forms including that row remove in data base.

VB.NET
Give me any one idea.


What I have tried:

How to delete selected row for data grid view in c# 2010 windows forms
Posted
Updated 19-Jul-16 3:29am

1 solution

try this

C#
private void btnDelete_Click(object sender, EventArgs e)
       {
           int IdColumn = 0; // enter the correct value for Id Column or the column which you are using it for deleting..
           foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
           {
               dataGridView1.Rows.RemoveAt(row.Index);
               int id = Convert.ToInt32(row.Cells[IdColumn].Value);
               // write your sql command to delete this id
               //
           }
       }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900