Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


VB.net DatGridView problem populating multiple cells

Posted on 2014-08-29
Medium Priority
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:Murray Brown
  • 3
  • 2
LVL 27

Expert Comment

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

Author Comment

by:Murray Brown
ID: 40293114
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

ID: 40293629
How many elements are there in arrsplitrows and are all the elements numbers?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

by:Murray Brown
ID: 40294119
Hi. There are around 65 elements and they are all numbers
LVL 15

Accepted Solution

ChloesDad earned 2000 total points
ID: 40294161
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

by:Murray Brown
ID: 40310675
Thanks. Sorry about the late reply

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

578 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