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

Posted on 2012-08-19
Last Modified: 2012-09-08

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, ";" _
                                                        & "user id=vbnet;" _
                                                        & "password=password;" _
                                                        & "database=admin")
            Dim dTable As New DataTable
            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

    End Sub

Open in new window

Question by:prowebinteractiveinc
    LVL 10

    Expert Comment

    Just so I'm clear, is this a WinForm app?
    LVL 18

    Accepted Solution

    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
            End If
        End Sub

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now