我想知道是否可以根据特定条件更改datagridview中的图像按钮?我想根据状态值更改datagridview内按钮的图像。如果状态为有效,我想将其更改为绿点,如果状态为(无效),则将其更改为红点 这是我的代码:
If dgridPatient.Columns(e.ColumnIndex).Name = "btnStatus" AndAlso e.RowIndex >= 0 Then
Try
If dgridPatient.Rows.Count >= 1 Then
For i As Integer = 0 To dgridPatient.Rows.Count
'If Not IsDBNull(dgridPatient.Rows(i).Cells(8).Value) _
' AndAlso dgridPatient.Rows(i).Cells(8).Value.Equals("Active") Then
If (dgridPatient.Rows(i).Cells("Status").Value.ToString = "Inactive") Then
e.Paint(e.CellBounds, DataGridViewPaintParts.All)
e.Graphics.DrawImage(My.Resources.icons8_Filled_Circle_3, CInt((e.CellBounds.Width / 2) - (My.Resources.icons8_Filled_Circle_3.Width / 2)) + e.CellBounds.X, CInt((e.CellBounds.Height / 2) - (My.Resources.icons8_Filled_Circle_3.Height / 2)) + e.CellBounds.Y)
e.Handled = True
Else
e.Paint(e.CellBounds, DataGridViewPaintParts.All)
e.Graphics.DrawImage(My.Resources.icons8_Filled_Circle_5, CInt((e.CellBounds.Width / 2) - (My.Resources.icons8_Filled_Circle_5.Width / 2)) + e.CellBounds.X, CInt((e.CellBounds.Height / 2) - (My.Resources.icons8_Filled_Circle_5.Height / 2)) + e.CellBounds.Y)
e.Handled = True
Exit Sub
End If
Next
End If
Catch ex As Exception
MessageBox.Show(e.ToString)
End Try
End If
答案 0 :(得分:0)
据我所知,Datagridview按钮本身没有“图像”按钮。 但是您可以在这里阅读最后两篇文章 https://social.msdn.microsoft.com/Forums/vstudio/en-US/f7f4fa33-5aed-4074-a4cd-ebf43dd8362c/image-button-in-datagridview?forum=vbgeneral
这样,您可以将不同的图像放置为活动或不活动