I have a datagridview being loaded from a datatable. It holds a list of a customers open invoices. I have a checkbox column for the first column. The user can check off any number of rows in order to apply a payment to one or more of the open invoices. The datagridview's EditMode is edit on enter since, I allow users to press enter on a row and the last column becomes into edit mode so that the user can type in the amount of money the customer would like to apply to each invoice. All the editing is not inorder to go back to the datasource, it's just visual so that the user can see all checked open invoices and the amount of payment the customer would like to pay for each invoice. When the user checks off an invoice, it goes into the CellContentClick event handler, and this is my code:
private void dgvOpenInvoices_CellContentClick(object sender, DataGridViewCellEventArgs e){
if (e.RowIndex == -1) return;
if (e.ColumnIndex != 0) return;
dgvOpenInvoices.EndEdit();
CheckedRows.Clear();
decimal amountDue = 0;
if (Convert.ToBoolean(dgvOpenInvoices.CurrentRow.Cells[0].Value) == false)
{
dgvOpenInvoices.CurrentRow.Cells["Payment"].Value = 0.00M;
}
else
{
amountDue = Convert.ToDecimal(dgvOpenInvoices.CurrentRow.Cells["AmountDue"].Value);
AssumedAmountCustomerWouldLikeToPay(amountDue, dgvOpenInvoices.CurrentRow.Index);
}
decimal amount = 0;
decimal invAmounts = 0;
foreach (DataGridViewRow row in dgvOpenInvoices.Rows)
{
if (Convert.ToBoolean(row.Cells[0].Value) == true)
{
CheckedRows.Add(row);
amount += Convert.ToDecimal(row.Cells["Payment"].Value);
invAmounts += Convert.ToDecimal(row.Cells["AmountDue"].Value);
}
}
AmountAvailable(paymentCreditAmount - amount);
InvoiceAmounts(invAmounts);
if (gAssumeAnAmount)
{
AssumedAmountCustomerWouldLikeToPay(amountDue, e.RowIndex);
}
}
I tell it to endEdit so that the value of the textbox is correct. I noticed though that I can't click more than one row at a time. As soon as I check one row the other checked row gets unchecked. When I changed EditMode to edit on keystroke that didn't happen, but then I can't edit the payment amount column on an enter click.
Debra has a question