Datagrid
-
I have use a datagrid in my sales software, now when the user select any item and qty i want to calculate its value in another columns. say for example: Col "Items" Col "Qty" Col "Rate" Col "Total Value" - I want to calculate the total value. Thanks, Sohil Masani
-
I have use a datagrid in my sales software, now when the user select any item and qty i want to calculate its value in another columns. say for example: Col "Items" Col "Qty" Col "Rate" Col "Total Value" - I want to calculate the total value. Thanks, Sohil Masani
Here is a code snippet that I found online a while ago that helps: Try this code in DataGrid CellEndEdit Events (note: this will sum the items not multiply. So you will just modify it to check whether the cells have values and then multiply the values. i am to lazy to retype it)
Dim iTotal As Integer = 0
With DataGrid1
For i As Integer = 0 To .ColumnCount - 2
If Not IsDBNull(.Rows(e.RowIndex).Cells(i).Value) Then
iTotal += .Rows(e.RowIndex).Cells(i).Value
End If
Next
.Rows(e.RowIndex).Cells(.ColumnCount - 1).Value = iTotal
End Withmodified on Wednesday, January 27, 2010 2:59 AM
-
I have use a datagrid in my sales software, now when the user select any item and qty i want to calculate its value in another columns. say for example: Col "Items" Col "Qty" Col "Rate" Col "Total Value" - I want to calculate the total value. Thanks, Sohil Masani
Hi Sohil, You can use the Datagridview_CellEndEdit() for manipulating the calculations. For example, from the below, suppose your "qty" column number is 3 or your "rate" column is 4 then, it can be...like the following Private Sub MyDataGrid1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MyDataGrid1.CellEndEdit If e.ColumnIndex = 3 or e.columnIndex = 4 Then Try MyDataGrid1.CurrentRow.Cells("total value").Value = MyDataGrid1.CurrentRow.Cells("qty").Value * MyDataGrid1.CurrentRow.Cells("rate").Value Catch ex As Exception End Try End If End Sub