views:

63

answers:

2

Hi,

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,

+1  A: 

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;
    }
David Neale
I am unable to add an event handler which take DatagridViewCellEventArgs for bindingNavigatorDeleteItemalso, bindingNavigator does not have such CellValueChanged Event. I think this can work if I use it for DataGridView like : public void DataGridView_CellValueChanged(...)
Jin
A: 

For my Question #1.

  • change "DeleteItem" property of BindingNavigator to (none)
  • create an eventhandler of "DeleteItem_Clicked"
  • get current row number by

    int cRow = gridEventType.CurrentCell.RowIndex;

  • delete the current item from bindingsource

    BindingNavigator.BindingSource.RemoveCurrent();

Jin