Dim sum As Double = 0.0
If (e.ColumnIndex = 2 Or e.ColumnIndex = 3) Then
Try
Dim price As Double = Double.Parse(DataGridView1(2, e.RowIndex).Value.ToString())
Dim qty As Double = Double.Parse(DataGridView1(3, e.RowIndex).Value.ToString())
Dim amount As Double = price * qty
DataGridView1(4, e.RowIndex).Value = amount.ToString("#,###.00")
sum = sum + amount - OldValue
NewValue = NewValue + sum
txtTotal.Text = NewValue.ToString("#,###.00")
Catch ex As Exception
NewValue = NewValue - OldValue
txtTotal.Text = NewValue.ToString("#,###.00")
DataGridView1(4, e.RowIndex).Value = 0
End Try
End If
DataGridView1_CellBeginEdit
Code (VB.NET)
Try
OldValue = Double.Parse(DataGridView1(4, e.RowIndex).Value.ToString())
Catch ex As Exception
OldValue = 0
End Try
Tag : .NET, VB.NET, VS 2005 (.NET 2.x), VS 2008 (.NET 3.x), VS 2010 (.NET 4.x), VS 2012 (.NET 4.x)
Dim sum As Double = 0.0
If (e.ColumnIndex = 2 Or e.ColumnIndex = 3) Then
Try
Dim price As Double = Double.Parse(DataGridView1(2, e.RowIndex).Value.ToString())
Dim qty As Double = Double.Parse(DataGridView1(3, e.RowIndex).Value.ToString())
Dim amount As Double = price * qty
DataGridView1(4, e.RowIndex).Value = amount.ToString("#,###.00")
sum = sum + amount - OldValue
NewValue = OldValue + sum
txtTotal.Text = NewValue.ToString("#,###.00")
Catch ex As Exception
NewValue = NewValue - OldValue
txtTotal.Text = NewValue.ToString("#,###.00")
DataGridView1(4, e.RowIndex).Value = 0
End Try
End If