Resetting Checkbox back to UNCHECKED
In the following method I want to be able clear the checkboxes if the user clicks on the NO button of the Yes/No dialog box to confirm deletion of the checked records:
private void btnDelete_Click(object sender, System.EventArgs e) {
Cursor.Current = Cursors.WaitCursor;
//Data source defined from invoicelist.cs
DataTable chkInvoices;
//Identify the variable to use in the loop below to identify the records checked.
int Invoiceid = 0;
//Build the criteria for the message box.
StringBuilder InvoiceMsg = new StringBuilder();
DialogResult returnButtonSel;
chkInvoices = (DataTable)dataGrid1.DataSource;
int cntChkInvoices = 0;
while (cntChkInvoices < chkInvoices.Rows.Count)
{
if ((bool)chkInvoices.Rows[cntChkInvoices]["add"])
{
InvoiceMsg.Append(Convert.ToInt32(chkInvoices.Rows[cntChkInvoices]["invoiceid"]) + "\n\t" );
}
cntChkInvoices ++;
}
if (InvoiceMsg.Length > 1)
{
returnButtonSel = System.Windows.Forms.MessageBox.Show(this,"Delete Checked Invoices?", "Confirm Delete", System.Windows.Forms.MessageBoxButtons.YesNo,Syste m.Windows.Forms.MessageBoxIcon.Warning);
}
else
{
returnButtonSel = MessageBox.Show("No Invoices Selected");
}
if( returnButtonSel == DialogResult.Yes)
{
//MessageBox.Show(returnButtonSel + "");
cntChkInvoices = 0;
while (cntChkInvoices < chkInvoices.Rows.Count)
{
if ((bool)chkInvoices.Rows[cntChkInvoices]["add"])
{
Invoiceid = Convert.ToInt32(chkInvoices.Rows[cntChkInvoices]["invoiceid"]);
// Create new instance of the Invoice class from Invoice.cs
Invoice inv = new Invoice( Invoiceid, usersToken );
}
cntChkInvoices ++;
}
Load_Datagrid();
}
else
{
cntChkInvoices = 0;
while (cntChkInvoices < chkInvoices.Rows.Count)
{
chkInvoices.Rows[cntChkInvoices]["add"] = false;
}
}
}
Any help or direction would be appreciated. Thank you.
|