基本上我想要的是当更改状态并更新它会改变更新单元格的颜色这里是我的代码:
Private Sub Btnupdate_Click(sender As Object, e As EventArgs) Handles btnupdate.Click
Try
Dim datePublish As String = Format(dtpDatePublish.Value, "yyyy-MM-dd")
If txtAccessionNo.Text = "" Or txtAuthor.Text = "" Or txtTitle.Text = "" Or TxtBoxISBN.Text = "" Or txtPublisher.Text = "" Or CBSection.Text = "" Or TxtBoxSubject.Text = "" Or TxtBoxYearPub.Text = "" Or TxtBoxShelf.Text = "" Or TxtBoxCallNumber.Text = "" Then
MsgBox("All fields are required to be filled up.", MsgBoxStyle.Exclamation)
Else
sql = "SELECT * FROM `books` WHERE `AccessionNo` = '" & txtAccessionNo.Text & "'"
reloadtxt(sql)
If dt.Rows.Count > 0 Then
panelstatus.Visible = True
sqledit = "UPDATE `books` SET `Isbn`='" & TxtBoxISBN.Text & "',
`BookSection` = '" & CBSection.SelectedItem & "', `Subject` = '" & TxtBoxSubject.Text & "', `Title` = '" & txtTitle.Text & "',
`Author` = '" & txtAuthor.Text & "', `JointAuthor` = '" & txtjointauthor.Text & "', `Publisher` = '" & txtPublisher.Text & "',
`YearPublish` = '" & TxtBoxYearPub.Text & "', `Edition` = '" & TxtBoxEdition.Text & "', `Volume` = '" & TxtBoxVolume.Text & "',
`Aquistion` = '" & CBAquisition.SelectedItem & "', `DateAquired` = '" & datePublish & "', `SponsorPrice` = '" & TxtBoxPrice.Text & "',
`Shelf` = '" & TxtBoxShelf.Text & "', `CallNumber` = '" & TxtBoxCallNumber.Text & "', `Remarks` = '" & TxtBoxRemarks.Text & "', `Status` = '" & CBstatus.SelectedItem & "' WHERE `AccessionNo` = '" & txtAccessionNo.Text & "'"
save_or_update(sql, sqladd, sqledit, "Books has been updated in the database.", "New books has been saved in the database.")
Call InventoryAdd_Load(sender, e)
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
这是我的单元格格式代码
Private Sub DtgList1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles dtgList1.CellFormatting
For Each row As DataGridViewRow In dtgList1.Rows
If row.Cells(17).Value = "Available" Then
row.DefaultCellStyle.ForeColor = Color.White
row.DefaultCellStyle.ForeColor = Color.Red
End If
Next
End Sub