Murray Brown
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_Setting s.lblConne ctionStrin g.Text)
oSQLAdapterBank = New SqlDataAdapter(sSQL, connection)
oSQLAdapterBank.Fill(oSQLT ableBank)
Me.dgvBank.DataSource = oSQLTableBank
End Sub
I am using the following code to load a DataGridView.
If I then run the single line Me.dgvBank.Rows(628).Cells
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_Setting
oSQLAdapterBank = New SqlDataAdapter(sSQL, connection)
oSQLAdapterBank.Fill(oSQLT
Me.dgvBank.DataSource = oSQLTableBank
End Sub
Where are you looping through the grid? This code only loads the DataGridView with data using your SQL statement.
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.Back Color = Color.Blue
Me.dgvBank.Rows(oRowIndex) .Cells(5). Value = oLinkID
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Next
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)
Me.dgvBank.Rows(oRowIndex)
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?
ASKER
Hi. There are around 65 elements and they are all numbers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. Sorry about the late reply