monica73174
asked on
VB.Net datagridview event handler error
I have two datagridviews on my form.
Datagrid one loads some data.
The user clicks on a row and the second datagridview is supposed to display the records based on the information in the first datagridview.
this doesn't seem to work and I get an error that says Operation cannot be performed in this event handler.
Here is my code that loads the first data grid
Sub fillUnmatched()
Dim i As Integer = 0
Dim cnUnmatched As New SqlConnection(connectionSt ring)
Dim sqlString As String = "SELECT orgAdvisorBenID, original_name, advisor_name, beneficial_name, institution_id " + _
"FROM advisor_beneficial " + _
"WHERE original_name IS NOT NULL AND institution_id IS NULL OR " + _
"institution_id = 0 " + _
"ORDER BY original_name"
cnUnmatched.Open()
Dim cmd As New SqlCommand(sqlString, cnUnmatched)
Dim rdr As SqlDataReader = cmd.ExecuteReader
While rdr.Read()
frmUnMatched.dtgUnmatched. Rows.Add()
frmUnMatched.dtgUnmatched. Rows(i).Ce lls("ID"). Value = rdr("orgAdvisorBenID")
frmUnMatched.dtgUnmatched. Rows(i).Ce lls("Title ").Value = rdr("original_name")
i += 1
End While
cnUnmatched.Close()
End Sub
Here is my code that triggers the load of the second datagridview:
Private Sub dtgUnmatched_CellContentCl ick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataG ridViewCel lEventArgs ) Handles dtgUnmatched.CellContentCl ick, dtgSuggestions.RowEnter
data.fillSuggestions(dtgUn matched.Ro ws(e.RowIn dex).Cells (0).Value)
End Sub
Here is my code that fills the second datagrid - The error happens here when I add a row.
Sub fillSuggestions(ByVal ItemID As String)
Dim i As Integer = 0
Dim fillSuggestions As New SqlConnection(connectionSt ring + ";Asynchronous Processing=true;MultipleAc tiveResult Sets=true" )
Dim strSQLString As String = "SELECT UnMatchedID, orgAdvisorBenID, advisor, beneficial " + _
" FROM suggestedMatches " + _
" Where orgAdvisorBenID = '" + ItemID + "' " + _
" ORDER BY advisor"
frmUnMatched.dtgSuggestion s.SuspendL ayout()
fillSuggestions.Open()
Dim cmd As New SqlCommand(strSQLString, fillSuggestions)
Dim rdr As SqlDataReader = cmd.ExecuteReader
While rdr.Read()
frmUnMatched.dtgSuggestion s.Rows.Add ()
frmUnMatched.dtgSuggestion s.Rows(i). Cells(0).V alue = rdr("UnMatchedID")
frmUnMatched.dtgSuggestion s.Rows(i). Cells(1).V alue = rdr("orgAdvisorBenID")
frmUnMatched.dtgSuggestion s.Rows(i). Cells(2).V alue = rdr("advisor")
frmUnMatched.dtgSuggestion s.Rows(i). Cells(3).V alue = rdr("beneficial")
i = i + 1
End While
frmUnMatched.dtgSuggestion s.ResumeLa yout()
fillSuggestions.Close()
End Sub
Datagrid one loads some data.
The user clicks on a row and the second datagridview is supposed to display the records based on the information in the first datagridview.
this doesn't seem to work and I get an error that says Operation cannot be performed in this event handler.
Here is my code that loads the first data grid
Sub fillUnmatched()
Dim i As Integer = 0
Dim cnUnmatched As New SqlConnection(connectionSt
Dim sqlString As String = "SELECT orgAdvisorBenID, original_name, advisor_name, beneficial_name, institution_id " + _
"FROM advisor_beneficial " + _
"WHERE original_name IS NOT NULL AND institution_id IS NULL OR " + _
"institution_id = 0 " + _
"ORDER BY original_name"
cnUnmatched.Open()
Dim cmd As New SqlCommand(sqlString, cnUnmatched)
Dim rdr As SqlDataReader = cmd.ExecuteReader
While rdr.Read()
frmUnMatched.dtgUnmatched.
frmUnMatched.dtgUnmatched.
frmUnMatched.dtgUnmatched.
i += 1
End While
cnUnmatched.Close()
End Sub
Here is my code that triggers the load of the second datagridview:
Private Sub dtgUnmatched_CellContentCl
data.fillSuggestions(dtgUn
End Sub
Here is my code that fills the second datagrid - The error happens here when I add a row.
Sub fillSuggestions(ByVal ItemID As String)
Dim i As Integer = 0
Dim fillSuggestions As New SqlConnection(connectionSt
Dim strSQLString As String = "SELECT UnMatchedID, orgAdvisorBenID, advisor, beneficial " + _
" FROM suggestedMatches " + _
" Where orgAdvisorBenID = '" + ItemID + "' " + _
" ORDER BY advisor"
frmUnMatched.dtgSuggestion
fillSuggestions.Open()
Dim cmd As New SqlCommand(strSQLString, fillSuggestions)
Dim rdr As SqlDataReader = cmd.ExecuteReader
While rdr.Read()
frmUnMatched.dtgSuggestion
frmUnMatched.dtgSuggestion
frmUnMatched.dtgSuggestion
frmUnMatched.dtgSuggestion
frmUnMatched.dtgSuggestion
i = i + 1
End While
frmUnMatched.dtgSuggestion
fillSuggestions.Close()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The second grid is unbound.
jpaulino