我的datagridviewimagecolumn不是以编程方式添加的,也是未绑定的。但其他文件是从我的数据库绑定的。我需要一个简单的if子句,以便警告图像只出现在库存少于20的行中。
发布于 2013-05-28 14:43:22
您可以通过datagridview_cellformatting事件进行尝试
假设您的DataGridViewImageColumn已经存在于Columnindex(0)中
Private Sub dgv_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgv.CellFormatting
Dim sHeader As String = dgv.Columns(e.ColumnIndex).Name
If sHeader = "stock" Then
If e IsNot Nothing Then
If e.Value IsNot Nothing Then
If e.Value < 20 then
Try
Dim img as Bitmap = new Bitmap("c:\images\littlemouse.jpg")
// Create DGV Image column
dgv.CurrentCell.Value = img;
dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value = img;
Catch ex As FormatException
e.Value = ""
End Try
End If
End If
End If
End If
End Sub
https://stackoverflow.com/questions/16792786
复制相似问题