Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net DatGridView problem populating multiple cells

Hi
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
                oSQLTableBank.Clear()
                Dim connection As New SqlConnection(Form_Settings.lblConnectionString.Text)
                oSQLAdapterBank = New SqlDataAdapter(sSQL, connection)
                oSQLAdapterBank.Fill(oSQLTableBank)
                Me.dgvBank.DataSource = oSQLTableBank
End Sub
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Where are you looping through the grid? This code only loads the DataGridView with data using your SQL statement.
Avatar of Murray Brown

ASKER

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
                    Try
                        Me.dgvBank.Rows(oRowIndex).Cells(5).Style.BackColor = Color.Blue
                        Me.dgvBank.Rows(oRowIndex).Cells(5).Value = oLinkID
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try

                End If

            Next
How many elements are there in arrsplitrows and are all the elements numbers?
Hi. There are around 65 elements and they are all numbers
ASKER CERTIFIED SOLUTION
Avatar of ChloesDad
ChloesDad
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. Sorry about the late reply