[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2012-08-19
2
Medium Priority
?
296 Views
Last Modified: 2012-09-08
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

0
Comment
Question by:prowebinteractiveinc
2 Comments
 
LVL 10

Expert Comment

by:gavsmith
ID: 38311294
Just so I'm clear, is this a WinForm app?
0
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 2000 total points
ID: 38311900
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

873 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