我能够使用combobox中输入的文本i更改图像的后色,但是当我将该数据保存在数据网格中时,背面颜色不会更改。
这是我的代码:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
On Error GoTo SaveErr
MachineHistoryBindingSource.EndEdit()
Machine_HistoryTableAdapter.Update(HistoryDataSet.Machine_History)
MessageBox.Show("OK Complete")
SaveErr:
Exit Sub
Dim tempcolor4 As String
Dim tempcolor1 As String
tempcolor4 = ComboBox4.Text
tempcolor1 = ComboBox1.Text
If tempcolor4.Equals("Running") And tempcolor1.Equals("1") Then
Form2.PictureBox15.BackColor = Color.Green
ElseIf tempcolor4.Equals("Stop") And tempcolor1.Equals("1") Then
Form2.PictureBox15.BackColor = Color.Red
ComboBox1.SelectedIndex = -1
ComboBox4.SelectedIndex = -1
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'HistoryDataSet.Machine_History' table. You can move, or remove it, as needed.
Me.Machine_HistoryTableAdapter.Fill(Me.HistoryDataSet.Machine_History)
'TODO: This line of code loads data into the 'HistoryDataSet.Machine_History' table. You can move, or remove it, as needed.
Me.Machine_HistoryTableAdapter.Fill(Me.HistoryDataSet.Machine_History)
'TODO: This line of code loads data into the 'HistoryDataSet.Machine_History' table. You can move, or remove it, as needed.
Me.Machine_HistoryTableAdapter.Fill(Me.HistoryDataSet.Machine_History)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
MachineHistoryBindingSource.MovePrevious()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
MachineHistoryBindingSource.AddNew()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
MachineHistoryBindingSource.MoveNext()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form15.Show()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Me.Close()
End Sub
End Class
您要在设置颜色之前退出该方法。
On Error GoTo SaveErr
MachineHistoryBindingSource.EndEdit()
Machine_HistoryTableAdapter.Update(HistoryDataSet.Machine_History)
MessageBox.Show("OK Complete")
SaveErr:
Exit Sub '<--- Right here
在vb.net中,我们进行了结构化错误处理... catch ...最后...结束尝试
Try
MachineHistoryBindingSource.EndEdit()
Machine_HistoryTableAdapter.Update(HistoryDataSet.Machine_History)
MessageBox.Show("OK Complete")
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try