Проблема с отображением общей цены в dataGridView
Прошу помочь с моей проблемой: хочу отобразить для каждого заказа свою отдельную общую сумму, которая получается при прибавлении цен побочной dataGridView. Переменная с общей суммой сохраняется в отдельном классе.
private void getCommonPrice()
{
decimal price = dgvSub.Rows.Cast<DataGridViewRow>().Sum(t => Convert.ToDecimal(t.Cells[3].Value));
txtCurrentPriceInfo std = new txtCurrentPriceInfo(price); // СОХРАНЕНИЕ ЗНАЧЕНИЯ;
txtCommonPrice.Text = Convert.ToString(std.commonPrice) + " грн";
}
private void shownInfo() // Связь двух dataGridView;
{
ds.Tables["list_orders"].DefaultView.RowFilter = $"[{dgvSub.Columns[0].HeaderText}] = {Convert.ToString(dataGridView.CurrentRow.Cells[1].Value)}";
dgvSub.DataSource = ds.Tables["list_orders"];
dgvSub.ClearSelection();
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
shownInfo();
getCommonPrice();
}
Класс, в котором сохраняется переменная:
class txtCurrentPriceInfo
{
public decimal commonPrice { get; set; }
public txtCurrentPriceInfo(decimal commonPrice)
{
this.commonPrice = commonPrice;
}
}
