Lim Hwei Ling
Lim Hwei Ling

Reputation: 13

how do i total the sum column and row from data table vb.net

Category   projectName[1]    projectName[2] ... total<br/>
cat[1]           0                1               ??<br/>
cat[2]           2                3               ??<br/>
..              ....           .....             .....<br/>
total           ??                ??              ??<br/>

Here is my code to display my category of projectName and cat row. The problems is I dont know how to get value to sum of total in the data table.

ExportDT.Columns.Add("Category")
        For Each ProjectRow As Data.DataRow In TempProjectDT.Rows
            ExportDT.Columns.Add(ProjectRow.Item("NameOfProject").ToString.Trim)

        Next
        Dim NewRow As Data.DataRow
        Dim ComplaintDV As New Data.DataView(TempComplaintDT)
        For Each CategoryRow As Data.DataRow In TempComplaintCatDT.Rows
            NewRow = ExportDT.NewRow
            NewRow.Item("Category") = CategoryRow.Item("Category").ToString
            For nLoop As Integer = 1 To ExportDT.Columns.Count - 1
                ComplaintDV.RowFilter = "ComplaintCategory='" & CategoryRow.Item("Category").ToString & "' AND NameOfProject='" & ExportDT.Columns(nLoop).ColumnName & "'"
                If ComplaintDV.Count > 0 Then
                    NewRow.Item(ExportDT.Columns(nLoop).ColumnName) = ComplaintDV.Count
                Else
                    NewRow.Item(ExportDT.Columns(nLoop).ColumnName) = "0"
                End If
            Next
            ExportDT.Rows.Add(NewRow)
        Next

Upvotes: 0

Views: 2349

Answers (1)

CodingSource
CodingSource

Reputation: 203

Let's make an assumption on this one:

For i As Integer = 0 To 2
    yourTable.Rows(i).Cells(2).Value = yourTable.Rows(i).Cells(0).Value + yourTable.Rows(i).Cells(1).Value
Next 

It lets you calculate the columns to Column3. The Column3 will show the sum.

Upvotes: 1

Related Questions