1
我有一個GridView(訂單)有三列:如何乘數據的GridView兩列,並顯示在另一列結果
- 價格
- 數量
- 總
我想要將Price
與Quantity
相乘,並在dataGridview的Total
列中顯示結果。
請記住:我的dataGridview沒有綁定任何表。
我想這個代碼來實現我的目標,但沒有被退回,這是不工作的手段價值:
private void totalcal()
{
// is the foreach condition true? Remember my gridview isn't bound to any tbl
foreach (DataGridViewRow row in gvSale.Rows)
{
int a = Convert.ToInt32(row.Cells[3].Value) * Convert.ToInt32(row.Cells[4].Value); // value is null why??
row.Cells[5].Value = a;
}
}
這是我點擊一個按鈕調用方法。 (這是不工作原因在我的代碼裏面定義)
而且我想知道哪個是適合此計算的Datagridview事件?我不想來計算按鈕,點擊總量
還是空不工作 –
你確定你的_Price_列索引是3和_數量_列索引是4? –
是的,你有沒有錯誤的感謝,但行填充行gridview我沒有找到什麼是適當的事件 –