public FormSubTotal() { this.InitializeComponent(); this.InitGrid1(); var dt = DataRepo.DataSubTotal(); this.dataGridView1.DataSource = dt; this.InitGrid2(dt.Copy()); this.dataGridView1.CellClick += (g, e) => { var row = this.dataGridView1.Rows[e.RowIndex]; var lastColumnIndex = this.dataGridView1.ColumnCount - 1; row.Cells[lastColumnIndex].Value = row .Cells .Cast <DataGridViewCell>() .Select((s, i) => i != lastColumnIndex ? s.Value : decimal.Zero) .Sum(s => (decimal)s); }; this.dataGridView1.SelectionChanged += (s, e) => { var row = this.dataGridView1.CurrentRow; if (row == null) { return; } var subTotal = (decimal)row.Cells["Nilai1"].Value + (decimal)row.Cells["Nilai2"].Value + (decimal)row.Cells["Nilai3"].Value; this.labelSelectedRow.Text = $@"Selected Row Total: {subTotal.ToString(CultureInfo.InvariantCulture)}"; }; }