Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a gridview in winform i am using this code to make copy of Gridview row and generate next row now i want to make coding that delete the row too.
C#
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
                       
if (e.RowIndex >= 0 && e.ColumnIndex==4 && ((DataGridView)sender).Columns[e.ColumnIndex].GetType() ==  typeof(DataGridViewButtonColumn))
              {
                  DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                  dataGridView1.Rows.Add(row);
               }
        }
Posted
Comments
VICK 31-Oct-13 1:29am    
Use Gridview's onRowCommand event for this purpose.

Hello ,

you can use Cell_click event of datagridview to delete any row from it.

try this..

C#
private void _dgvGridView_CellClick(object sender, DataGridViewCellEventArgs e)
       {
           if (e.RowIndex != _dgvGridView.NewRowIndex && e.ColumnIndex == 4) 
         //if delete column at 4th position
           {
               _dgvGridView.Rows.RemoveAt(e.RowIndex);              
           }
       }


thanks
animesh
 
Share this answer
 
OnRowCommand Event can be very helpful in your desired scenario or you can give a try to OnRowDeleting.
You can visit the following links to get further help.

Link1

Link2

Link3

Hope it will help. :)
 
Share this answer
 
Comments
Muhamad Faizan Khan 2-Nov-13 12:14pm    
i didin Find onRowCommand in winform's grid view

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