有人知道如何在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
如果有人知道,我将感激你的帮助。提前谢谢你。Kuldip .
你不妨看看下面的答案。我设法得到了一个完整的解决方案。
http://social.msdn.microsoft.com/forums/vstudio/en us/215e3c61 - 6 - a1e 4 f7d - 8 c53 - 534680 - fe2c87/display图像按钮- - - datagridview vbnet?forum=visualstudiogeneral
对
您可以使用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