Devphil Devphil - 1 year ago 128
Vb.net Question

C# DataGridView capturing deleted row

1.

I am using a DataGridView, which is bound to a dataset.
There is a bindingNavigator as well.

when a user deletes a row by clicking "bindingNavigatorDeleteItem" button, I am trying to get the row being deleted.

private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
int crow = gridEventType.CurrentCell.RowIndex;


but it returns the newly selected row AFTER deletion of a selected row.
so, If I have two rows
0
1
2
and I delete 2

crow is 1, not 2.

Am I missing something here?

2. How do I know whether certain rows are modified in datagridview?

Thanks,

Answer Source

You should be using the DataGridViewCellEventArgs.

private void bindingNavigatorDeleteItem_Click(object sender, 
                                                  DataGridViewCellEventArgs e) 
{
   int cRow =  gridEventType.Rows[e.RowIndex];

   //delete row from persisted storage

   //rebind data to persisted storage or remove row directly:
   gridEventType.Rows.RemoveAt(cRow);
}

For your second point, there's a CellValueChangedEvent.

    private void bindingNavigatorModifiedCell_CellValueChanged(object sender, 
                                                   DataGridViewCellEventArgs e)
    {
         //updated row
         int cRow = e.RowIndex;
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download