【问题标题】:DataGridView Image Button Cell - vb.NetDataGridView 图像按钮单元格 - vb.Net
【发布时间】:2014-08-07 13:24:53
【问题描述】:

有谁知道如何在 Visual Studio .Net 中使用 DataGridView 的图标来编写“删除图像按钮”

我很难找到试图让我的最后一列有一个删除图标而不是“删除”这个词,我想显示一个小垃圾箱图标。

我已经尝试在很多地方寻找,但我无法让它发挥作用。

Private Sub dataGridView1_CellPainting(ByVal sender As Object, ByVal e As 

    DataGridViewCellPaintingEventArgs)
        If e.ColumnIndex = 1 AndAlso e.RowIndex >= 0 Then
            e.Paint(e.CellBounds, DataGridViewPaintParts.All)
        Dim img As Image = Image.FromFile("C:\icon_delete.jpg")
            e.Graphics.DrawImage(img, e.CellBounds.Left + 10, e.CellBounds.Top + 5, 10, 10)
            e.Handled = True
        End If
    End Sub 

如果有人知道,将不胜感激。提前致谢。库尔迪普。

【问题讨论】:

    标签: .net vb.net datagridview imagebutton


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      您可以使用DataGridViewImageColumnDataGridView.CellFormatting 事件。

      Private Sub YourDataGridView_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvBilancioAttivita.CellFormatting
      
          If e.ColumnIndex = -1 Or e.RowIndex = -1 Then Exit Sub
      
          If YourDataGridView.Columns(e.ColumnIndex).Name = "YourDeleteColumn" Then
              e.Value = Image.FromFile("C:\icon_delete.jpg")
          End If
      
      End Sub
      

      【讨论】:

      • 非常感谢您非常感谢。我会去的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-30
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多