0

I have a DataGridView which includes a checkbox column for a Boolean variable in the database.

When I click on this checkbox, it fires the events below.

Inside the uiPersonGridView_CellValueChanged event, I call the Data Table Adapter Update method on the Persons Data Table which is the Datasource for the DataGridView.

The Update works fine, the second time but it will still not Update the Current Rows Data?

For example, if I had two rows, if I tick in the first rows check box; Update returns 0 rows updated for int i and I check the database and nothing has been changed. But if I tick on the second rows check box, the Update returns 1 row updated for int i - I check the database and the first record has changed and not the second?

How can I get it work so the update works for the initial change and changes thereafter?

    private void uiPersonGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
    {
        if (uiPersonGridView.IsCurrentCellDirty)
        {
            uiPersonGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
        }
    }

    private void uiPersonGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        if (uiPersonGridView.DataSource == null)
            return;

        if (e.RowIndex == -1)
            return;

        int i = _personAdapter.Update(_person);
    }
SamoanProgrammer
  • 954
  • 4
  • 13
  • 27

1 Answers1

0

What I had to do in order to get this working was set the datarow state to modified and this has done what I need it to do.

private void uiPersonGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
    if (uiPersonGridView.IsCurrentCellDirty)
    {
        uiPersonGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
           DataRowView drv = uiPersonGridView.CurrentRow.DataBoundItem as DataRowView;
            drv.Row.SetModified();
    }
} 
SamoanProgrammer
  • 954
  • 4
  • 13
  • 27