Calculation Total on Data Grid

mohdelhi

Member
Joined
Mar 2, 2005
Messages
7
Programming Experience
Beginner
Need your help in VB.NET datagrid,

I need to do calcultion on datagrid and will store in database.

Thanks
 
For each row add a column with an expression.
For each Column use datatable.compute("sum(columnname)","")

TPM
 
Dim Summary As New ArrayList()
Summary.Add("5,sum(AMOUNT)")
Summary.Add("6,sum(VAT_AMOUNT)")
' Map the array list to the SummaryColumns property of your DataGrid control.
SummaryCols = Summary

' Set the foreground color and the background color for the footer row.
'dg.FooterColor = Brushes.Brown
'dg.FooterFontColor = Brushes.White

' Bind the DataGrid control to the related data.
'dg.BindDataGrid()
MyDataTable = db.DataSet11.Tables(0)
'MyDataTable = ds.Tables(0)

MyDataTable.Columns.Add("ID", System.Type.GetType("System.Boolean"))
MyDataTable.Columns("ID").DefaultValue = True
MyDataTable.Columns("ID").ColumnMapping = MappingType.Hidden
----------------------------------------------------------

Dim data1(2) As Double
Dim im As Integer
im = 0
' Calculate the value for each cell in the footer.
Dim MyArray(2) As String
Dim MyString As String
Try
For Each MyString In SummaryCols
MyArray = MyString.Split(","c)
data1(im) = (MyDataTable.Compute(MyArray(1), "ID is null"))
im = im + 1
Next
InvoiceAmount.Text = (data1(0)).ToString()
VatAmount.Text = (data1(1)).ToString()
InvoiceVatAmount.Text = (data1(1)).ToString()
Dim totalv As Double
Dim totals As String
totalv = data1(0) + data1(1)
InvoiceTotalAmount.Text = totalv.ToString()
---------------------------------------------

This code generate sub-total when i click twice in check box of datagrid twice. How to make it autometically
 
Back
Top