首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于特定列文本的DataGridViewImageColumn图像

基于特定列文本的DataGridViewImageColumn图像
EN

Stack Overflow用户
提问于 2014-12-16 20:34:04
回答 1查看 2.2K关注 0票数 0

如何根据特定列中的文本将ImageColumn中的特定图像添加到DataGridView中?

示例:

Column1 Column2 Column3 ImageColumn

网站标题信息标志

我希望标志/形象被改变,并显示每个网站的“正确”标志,而不是相同的形象为所有网站。

我现在有这个添加漂亮的标志,但它只是添加相同的标志在每一行。

代码语言:javascript
复制
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:我现在使用以下代码:

代码语言:javascript
复制
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

似乎正在工作,但当我使用此代码时,图像不会发生任何更改:

代码语言:javascript
复制
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。我想我做错了什么,但看起来我走的路是对的。如果你想的话,可以用小费或片段打我,谢谢:-)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-17 13:54:31

在……里面

DataGridView1.CellFormatting

用这个:

代码语言:javascript
复制
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

当你看到我的代码有问题时请打我。谢谢大家:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27513434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档