I have a button that retrieves data and place the information in data grid, its currently working but I need to add a message box to it. If the back color in the grid is red when the button is click a message box pop up "Correct all red fields before continuing." I have tried to insert message boxes to test but in the for each loop the message box appeared for each red back color cell and that's not what I need it to do. I need it to search the entire grid for for red back color and display the message box.
Here is the code:
Here is the code:
Code:
Private Sub Retrieve()
On Error GoTo errH
Dim con As OdbcConnection
Dim cmd As OdbcCommand
Dim dr As OdbcDataReader
Dim strItem1 As String
Dim strItem2 As String
Dim strOdbc As String = ""
Dim hasRows As Boolean = False
Dim strItem3 As String
Dim strRelease As String
Dim sqlStr As String
Dim strDsn, strSystem As String
strDsn = ComboBox1.Text
strSystem = txtSystem.Text
strOdbc = "{iSeries As ODBC Driver};System=" + strSystem + ";Dsn=" + strDsn + ";Uid=TEST!;Pwd=Test;"
con = New OdbcConnection(strOdbc)
con.Open()
Using con
For Each dgvRow As DataGridViewRow In gridUserEntries.Rows
If (Not IsNothing(dgvRow.Cells(0))) Then
If (Not (IsNothing(dgvRow.Cells(0).Value))) Then
strRelease = dgvRow.Cells(0).GetEditedFormattedValue(dgvRow.Cells(0).RowIndex, DataGridViewDataErrorContexts.Display)
sqlStr = "Select * from jobscopedb.ppusrfs where search_key_uf= '" + strRelease + "'"
cmd = New OdbcCommand(sqlStr, con)
'con.Open()
dr = cmd.ExecuteReader()
hasRows = dr.HasRows
While (hasRows And dr.Read)
strRelease = dr.Item(0).ToString
strItem2 = dr.Item(2).ToString
strItem3 = dr.Item(3).ToString
If (strItem2.Contains("27 PRODWK")) Then
dgvRow.Cells(1).Value = dr.Item(3).ToString.Trim
End If
If (strItem2.Contains("28 SHIPMON")) Then
dgvRow.Cells(2).Value = dr.Item(3).ToString.Trim
End If
If (strItem2.Contains("30 %COMPL")) Then
dgvRow.Cells(3).Value = dr.Item(3).ToString.Trim
End If
If (strItem2.Contains("31 TGTSHIP")) Then
dgvRow.Cells(4).Value = dr.Item(3).ToString.Trim
End If
If (strItem2.Contains("70 SCHPROD")) Then
dgvRow.Cells(5).Value = dr.Item(3).ToString.Trim
End If
If (strItem2.Contains("81 AB%")) Then
dgvRow.Cells(6).Value = dr.Item(4).ToString.Trim
End If
If (strItem2.Contains("82 ARM%")) Then
dgvRow.Cells(7).Value = dr.Item(4).ToString.Trim
End If
If (strItem2.Contains("83 SHAFT%")) Then
dgvRow.Cells(8).Value = dr.Item(4).ToString.Trim
End If
If (strItem2.Contains("84 FIT% ")) Then
dgvRow.Cells(9).Value = dr.Item(4).ToString.Trim
End If
If (strItem2.Contains("85 HDW%")) Then
dgvRow.Cells(10).Value = dr.Item(4).ToString.Trim
End If
If (strItem2.Contains("86 FIN% ")) Then
dgvRow.Cells(11).Value = dr.Item(4).ToString.Trim
End If
If (strItem2.Contains("87 WELDCMP")) Then
dgvRow.Cells(12).Value = dr.Item(3).ToString.Trim
End If
End While
cmd.Dispose()
End If
End If
Next
End Using
Exit Sub
errH:
MsgBox(Err.Description)
con = Nothing
End Sub