Adrian Serafin
Adrian Serafin

Reputation: 7715

Bound DataGridViewCheckBoxColumn not updating binding source

I have DataGridView bound to a bindingsource with datasource as a list of active record models:

    BindingSource bs = new BindingSource();
    bs.DataSource = _user.Addresses;

Address has bool property named Actual, and my DataGridView has CheckBoxColumn:

    DataGridViewCheckBoxColumn c = new DataGridViewCheckBoxColumn(false);
    c.Name = "actualColumn";
    c.HeaderText = "Aktualny";
    c.DataPropertyName = "Actual";
    c.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
    addressesDataGridView.Columns.Add(c);

Data from database is displayed properly.

When I click on checked checkbox cell and uncheck it and then go to save button, property Actual in my bindingsource isn't unchecked.

When I click on checked checkbox cell and uncheck it and change row selection and then click save, button changes are visible in bindingsource.

Does a workaround exist for this issue?

Upvotes: 3

Views: 5279

Answers (1)

fridrikr
fridrikr

Reputation: 48

The problem is that the datagrid is not updating the underlying datasource.

You could try calling BindingSource.EndEdit as the first thing in the Save functionality.

You could also try to call EndCurrentEdit on the CurrencyManager that is bound to the control. To access it you do:

myCurrencyManager = (CurrencyManager)this.BindingContext[myTable];

Upvotes: 2

Related Questions