Home:ALL Converter>DataGridView DataSource not updating with SelectAll checkbox method

DataGridView DataSource not updating with SelectAll checkbox method

Ask Time:2012-09-22T00:17:48         Author:Samuel Parkinson

Json Formatter

I have the following code that runs on the CheckedChanged event of a checkbox.

/// <summary>
/// Determine whether to select all order records
/// </summary>
/// <param name="sender">determine sender object</param>
/// <param name="e">event args</param>
private void CbSelectAll_CheckedChanged(object sender, EventArgs e)
    if (this.dgvOrderLines.Rows.Count != 0)
        bool value = this.CbSelectAll.Checked;

        for (int i = 0; i < this.dgvOrderLines.RowCount; i++)
            this.dgvOrderLines[0, i].Value = value;

        if (value)
            this.btnFailed.Enabled = true;
            this.BtnDownload.Enabled = true;
            this.btnFailed.Enabled = false;
            this.BtnDownload.Enabled = false;

The problem is this doesn't seem to actually update the underlining DataSource. The checkbox column that it loops through visually updates fine.

So when I do the following, after a user presses a button, the selected rows all still have a false value in the checkbox column.

Order[] orderlines = ((SortableBindingList<Order>)this.dgvOrderLines.DataSource).Where(x => x.Include == true).ToArray();

Any idea's as to where I'm going wrong?

Author:Samuel Parkinson,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12534274/datagridview-datasource-not-updating-with-selectall-checkbox-method