Trying to get contents of "Amount column" and loop through all rows

Hi.

I have pasted my current code down below:

I am trying get the monetary value in the 3rd column and loop through all rows. and set the additioned value in a textbox. Im trying to fire this when the corresponding Row Header is selected.
someone please help me....
Thanks in advance
    Public Sub fetchCustomersInvoices(ByVal customerId As String)
        Dim CommandText = "SELECT DATE_FORMAT(invoiceDate, '%b %d %Y') AS invDate, CONCAT(invoiceId, DATE_FORMAT(invoiceDate, '%Y%m%d'), customerId) AS invoiceNumber, Amount FROM invoices WHERE customerId='" & customerId & "'"

        Dim dbadp As New MySqlDataAdapter(CommandText, "server=myDomain.com;" _
                                                        & "user id=vbnet;" _
                                                        & "password=password;" _
                                                        & "database=admin")
        Try
            Dim dTable As New DataTable
            dbadp.Fill(dTable)
            dbadp.Dispose()
            DataGridView3.DataSource = dTable
            DataGridView3.Columns(0).HeaderText = "Inv. Number"
            DataGridView3.Columns(1).HeaderText = "Inv. Date"
            DataGridView3.Columns(2).HeaderText = "Amount"

        Catch myerror As MySqlException
            MessageBox.Show(CommandText & " ==> " & myerror.Message)
        End Try
        GroupBox8.Visible = True
    End Sub

Open in new window


I tried to get it threw e.RowIndex, but it returns a negative number: below is the code
    Private Sub DataGridView3_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellContentClick

        MessageBox.Show(e.RowIndex)
    End Sub

Open in new window

prowebinteractiveincAsked:
Who is Participating?
 
UnifiedISCommented:
I would try the RowHeaderMouseClick event instead

You'll probably want to make sure row index is not -1 before calling your other method

something like this:
Private Sub DataGridView3_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView3.RowHeaderMouseClick
        If e.RowIndex > -1 Then
            Dim dgr As DataGridViewRow = Me.DataGridView3.Rows(e.RowIndex)
            'call your method
            fetchCustomersInvoices(dgr.Cells("customerId"))
        End If
    End Sub
0
 
gavsmithCommented:
Just so I'm clear, is this a WinForm app?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.