簡體   English   中英

DataGridView圖像按鈕單元格-vb.Net

[英]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。

您可以使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM