Does anyone have the answer to these 2 questions?

piscis

Well-known member
Joined
Jun 30, 2003
Messages
54
Gentlemen:

Does anyone have the answer to these 2 questions?

1. How to sum only those records for the month of March in column 4 in datagrid1 and display it in a textbox3 located in a Tab Control #2 named
 
Hi piscis,

Here is something to give you an idea:
For Question 1

Code:
            Dim ds As DataSet = Me.DataSource
            where "Me" is the datagrid
            Dim rowCount As Integer = ds.Tables(0).Rows.Count()
            Dim col As Integer = 4
            Dim row As Integer
            Dim dsum as double

            For row = 0 To rowCount - 1
                If IsNumeric(Me.Item(row, col)) Then
                    dsum = dsum + CLng(IIf(IsDBNull(Me.Item(row, col)), "0", Me.Item(row, col)))
                End If
            Next row
This code above just tells you how to sum everything in column 4.

A really good source for this is posted on this forum, but here is the direct link:

http://www.syncfusion.com/FAQ/WinForms/default.asp

Regards,

georg
 
georg:

Do you know why Im getting this error?

On this line:
Code:
If IsNumeric(Me.Item(row, col)) Then

Error: Item is not a member of Project.frmMain

Code:
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim ds As DataSet = Me.DsBrio250Table5
        where "Me" is the datagrid
        Dim rowCount As Integer = ds.Tables(0).Rows.Count()
        Dim col As Integer = 4
        Dim row As Integer
        Dim dsum As Double

        For row = 0 To rowCount - 1
            If IsNumeric(Me.Item(row, col)) Then
                dsum = dsum + CLng(IIf(IsDBNull(Me.Item(row, col)), "0", Me.Item(row, col)))
            End If
        Next row
    End Sub
 
Dont use Me, me references the form not the datagrid, use the name of the datagrid in stead of me and everything will work fine
 
Back
Top