Solved DatGridView problem populating multiple cells

Posted on 2014-08-29
Last Modified: 2014-09-08
I am using the following code to load a DataGridView.
If I then run the single line    Me.dgvBank.Rows(628).Cells(5).Value = 63
it works, but if I loop through and try to populate multiple lines they don't hold the value
Not sure why

    Public oSQLAdapterBank As SqlDataAdapter
    Public oSQLTableBank As New DataTable
Sub Load
        Dim sSQL As String
            sSQL = "Select * From BANK"

          Me.cmbSQLTables.Visible = True
                Dim connection As New SqlConnection(Form_Settings.lblConnectionString.Text)
                oSQLAdapterBank = New SqlDataAdapter(sSQL, connection)
                Me.dgvBank.DataSource = oSQLTableBank
End Sub
Question by:murbro
    LVL 25

    Expert Comment

    by:Shaun Kline
    Where are you looping through the grid? This code only loads the DataGridView with data using your SQL statement.

    Author Comment

    I gather the row index and the integer that I want to populate the cell with then populate as follows
                Dim arrSplitRows As Object = Split(strRowIndices, ",")
                Dim arrSplitLinkIDs As Object = Split(strLinkIDs, ",")
                Dim oRowIndex As Long
                Dim oLinkID As Long

                For i = 0 To UBound(arrSplitRows)
                    'If i = 77 Then Stop
                    oRowIndex = CLng(arrSplitRows(i))
                    oLinkID = CLng(arrSplitLinkIDs(i))
                    If IsNumeric(oRowIndex) = True And IsNumeric(oLinkID) = True Then
                            Me.dgvBank.Rows(oRowIndex).Cells(5).Style.BackColor = Color.Blue
                            Me.dgvBank.Rows(oRowIndex).Cells(5).Value = oLinkID
                        Catch ex As Exception
                        End Try

                    End If

    LVL 15

    Expert Comment

    How many elements are there in arrsplitrows and are all the elements numbers?

    Author Comment

    Hi. There are around 65 elements and they are all numbers
    LVL 15

    Accepted Solution

    OK, there is nothing that appears wrong. Have you stepped through the code and looked at the values of oRowIndex and oLinkID as the code executes?

    Do the values appear and then get overwritten? If that's the case then this code is probably right, and something else is overwriting your values with something else.

    Author Closing Comment

    Thanks. Sorry about the late reply

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    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…
    This video discusses moving either the default database or any database to a new volume.

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now