Vb.net 使用组合框更改图像的背面颜色,并将数据保存到数据网格视图
我可以使用在组合框中输入的文本更改图像的背景色,但当我将数据保存到数据网格中时,背景色不会更改 这是我的密码:Vb.net 使用组合框更改图像的背面颜色,并将数据保存到数据网格视图,vb.net,winforms,Vb.net,Winforms,我可以使用在组合框中输入的文本更改图像的背景色,但当我将数据保存到数据网格中时,背景色不会更改 这是我的密码: Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click On Error GoTo SaveErr MachineHistoryBindingSource.EndEdit() Machi
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
我删除了“出错时转到SaveErr”和SaveErr。因为发生了一个错误,当前背景颜色正在更改,但问题数据未保存在数据网格中。请尝试再次运行.Fill。顺便说一句,在Form1\u负载中,似乎您正在填充相同的内容3次。尝试删除其中的2个。我相信我回答了你原来的问题,所以请接受我的答案,并在答案左边打勾。数据库是否反映了这些更改?
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