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;
}
else
{
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?
So it turns out that the above method was working perfectly fine.
Coming back to it after the weekend I see that oddly the method is being called before we process the stuff we want, not after.
It was a case of resetting the gui for new data too early.