我一直在環顧網上尋找一些有用的指南,但我發現非 - 我如何在行中多個兩個數字,記住該值,然後對其餘行進行相同操作datagridview和所有這些值相加在一起。並在textbox
中總顯示。這兩列使用SqlCommand
顯示。但我想改變textbox
中的值,每次在列pocet
datagridview中進行更改(當我在datagridview中進行更改時,它不會將值插入到SQL中)。所以我毫不猶豫地在前面的問題here和用戶varocarbas問你 - 我非常感謝他花費的時間。在2個datagridview列乘以數據
他想出了這個代碼:
void calculateProductTwoColumns(int castkaIndex, int pocetIndex, int tot_rows)
{
try
{
double[] outVals = new double[tot_rows + 1];
int curRow = 0;
foreach (DataGridViewRow row in dtg_ksluzby.Rows)
{
curRow = curRow + 1;
outVals[curRow] = (double)row.Cells[castkaIndex].Value * (double)row.Cells[pocetIndex].Value;
kpriplac.Text = outVals.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show("" + ex.Message.ToString());
}
}
於是,我就「完善」它,使其工作就像我的願望,但我想我有點搞砸了。我想在每一行中添加pocet(dgv index 3)和cena(dgv index 2)。因此,我調用這個方法是這樣的:
calculateProductTwoColumns(2, 3, 4);
當我開始調試,它說:Specified cast is not valid.
我試着用斷點來調試,但我找不到,我沒有犯錯。
pocet是int和castka是數值數值(15,2)
謝謝你這麼多你的時間讀這篇文章,我會很高興與任何comentary或參考指南。
的DataGridView是數據綁定或行手動添加? –
@SriramSakthivel與SqlCommand,謝謝你的時間。 –
找不到你。使用DataSource? –