Augusto Accorsi
Augusto Accorsi

Reputation: 327

Delete GridView Row in Windows Forms

I have a GridView and in each item of this grid I have a Button that I use to delete the row of these button. But it is not working.

private void grvOrders_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        var senderGrid = (DataGridView)sender;                   

        if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
            e.RowIndex >= 0)
        {
           grvOrders.Rows.Remove(sender);
        }
    }

anyone could help me?

Upvotes: 2

Views: 2341

Answers (1)

DrewJordan
DrewJordan

Reputation: 5314

Your problem is you can't remove the sender: it's not a DataGridViewRow. Instead, use grvOrders.Rows.RemoveAt(e.RowIndex);.

Upvotes: 4

Related Questions