如何根据特定列中的文本将ImageColumn中的特定图像添加到DataGridView中?
示例:
Column1 Column2 Column3 ImageColumn
网站标题信息标志
我希望标志/形象被改变,并显示每个网站的“正确”标志,而不是相同的形象为所有网站。
我现在有这个添加漂亮的标志,但它只是添加相同的标志在每一行。
Dim img As New DataGridViewImageColumn()
Dim inImg As Image = PictureBox1.Image
img.Image = inImg
DataGridView1.Columns.Add(img)
img.HeaderText = "Website"
img.Name = "img"我试图将这段代码包装成"if DataGridView1........contains“,但我只创建了错误。有人能告诉我如何解决这个问题吗?
谢谢:-)
UPDATE:我现在使用以下代码:
Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If DataGridView1.Rows.Count > 0 Then
If e.ColumnIndex = 2 Then
Dim LINK = DataGridView1.Rows(e.RowIndex).Cells(0).Value
If LINK.ToString.Contains("test.nl") Then
DataGridView1.Rows(e.RowIndex).Cells(5).Value = PictureBox1.Image
End If
End If
End If
End Sub似乎正在工作,但当我使用此代码时,图像不会发生任何更改:
Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If DataGridView1.Rows.Count > 0 Then
If e.ColumnIndex = 2 Then
Dim LINK = DataGridView1.Rows(e.RowIndex).Cells(0).Value
If LINK.ToString.Contains("test.nl") Then
DataGridView1.Rows(e.RowIndex).Cells(5).Value = PictureBox1.Image
End If
If LINK.ToString.Contains("test.com") Then
DataGridView1.Rows(e.RowIndex).Cells(5).Value = PictureBox2.Image
End If
End If
End If
End Sub所有的图像都一样..。他们都使用pictureboximage2。我想我做错了什么,但看起来我走的路是对的。如果你想的话,可以用小费或片段打我,谢谢:-)
发布于 2014-12-17 13:54:31
在……里面
DataGridView1.CellFormatting
用这个:
If DataGridView1.Rows.Count > 0 Then
Dim LINK = DataGridView1.Rows(e.RowIndex).Cells(0).Value
If LINK.ToString.Contains("test.nl") Then
DataGridView1.Rows(e.RowIndex).Cells(5).Value = PictureBox1.Image
End If
If LINK.ToString.Contains("test.com") Then
DataGridView1.Rows(e.RowIndex).Cells(5).Value = PictureBox2.Image
End If
End If当你看到我的代码有问题时请打我。谢谢大家:)
https://stackoverflow.com/questions/27513434
复制相似问题