我有一个名为“ txtCustomersPaymentsRemains”的文本框 和名为“ dgvCustomersPayments”的datagridview
我想将此语句转换为c#代码
txt1
txt1.text = row0.col2
如果
row0.col2 = row0.col1
然后
row1.col2 =(txt1-row0.col2)
以此类推....
我尝试了此代码,它可以工作,但我想自动对行进行计数
private void txtCustomersPaymentsAmount_Validated(object sender, EventArgs e)
{
if (txtCustomersPaymentsBalances.Text != null && txtCustomersPaymentsBalances.Text != "")
{
txtCustomersPaymentsRemains.Text = Convert.ToString(Math.Round(Convert.ToDecimal(txtCustomersPaymentsBalances.Text) - Convert.ToDecimal(txtCustomersPaymentsAmount.Text)));
dgvCustomersPayments.Rows[0].Cells["Payments"].Value = Convert.ToDecimal(txtCustomersPaymentsAmount.Text);
if (Convert.ToDecimal(txtCustomersPaymentsAmount.Text) > Convert.ToDecimal(dgvCustomersPayments.Rows[0].Cells["الرصيد المدين"].Value))
{
dgvCustomersPayments.Rows[1].Cells["Payments"].Value = Math.Round(Convert.ToDecimal(dgvCustomersPayments.Rows[0].Cells["Payments"].Value) - Convert.ToDecimal(dgvCustomersPayments.Rows[0].Cells["الرصيد المدين"].Value));
dgvCustomersPayments.Rows[0].Cells["Payments"].Value = Convert.ToDecimal(dgvCustomersPayments.Rows[0].Cells["الرصيد المدين"].Value);
}
}
}