[英]DataGridView Image Button Cell - vb.Net
有谁知道如何在Visual Studio .Net中使用DataGridView的图标来设置“删除图像按钮”
我正在努力寻找使我的最后一列具有删除图标而不是单词“ Delete”的方法,并且我想显示一个小垃圾桶图标。
我尝试在许多地方进行搜索,但无法正常工作。
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
如果有人知道,将不胜感激。 提前致谢。 Kuldip。
您可以使用DataGridViewImageColumn和DataGridView.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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.