vb.net 更改 datagridviewimagecolumn 中特定行的图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16792786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change image for specific rows in datagridviewimagecolumn
提问by joshua
my datagridviewimagecolumn is not programmatically added and also unbounded. But the other files are bounded from my database. I need a simple if clause statement so that the warning image would only appear to rows with stock less than 20.
我的 datagridviewimagecolumn 不是以编程方式添加的,也没有限制。但是其他文件受我的数据库限制。我需要一个简单的 if 子句语句,以便警告图像只会出现在库存少于 20 的行中。
回答by matzone
You can try it by datagridview_cellformatting event
你可以通过 datagridview_cellformatting 事件试试
Assumed that you already have your DataGridViewImageColumn in Columnindex(0)
假设您已经在 Columnindex(0) 中拥有 DataGridViewImageColumn
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

