Delete a Row from a DataGridView given its index

Posted by Ruben Trancoso on Stack Overflow See other posts from Stack Overflow or by Ruben Trancoso
Published on 2009-11-02T18:45:26Z Indexed on 2010/05/23 2:00 UTC
Read the original article Hit count: 280

My DataGridView is a single line selection and theres a rowEnter Event where I get the line index every time the selected line changes.

    private void rowEnter(object sender, DataGridViewCellEventArgs e)
    {
        currentRowIndex = e.RowIndex;
    }

when I press a delete button I use the same index to delete the row

            myDataSet.Avaliado.Rows[currentRowIndex].Delete();
            avaliadoTableAdapter.Update(myDataSet.Avaliado);

it works fine if no column in the DataGridView is sorted, otherwise a get an error. What should be the way to know the row index in the dataset that corresponds to the rowindex from the DataGridView?

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms