How to display an image in a datagridview column header?

前端 未结 4 562
傲寒
傲寒 2020-12-03 15:40

At run-time, I am adding a DataGridView to a windows form. The final column is a DataGridViewImageColumn:

Dim InfoIconColumn As New         


        
4条回答
  •  长情又很酷
    2020-12-03 16:06

    try this code:

        Private Sub DataGridView1_CellPainting(ByVal sender As System.Object, _
                ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) _
                Handles DataGridView1.CellPainting
            If e.RowIndex = -1 AndAlso e.ColumnIndex = DataGridView1.Columns.Count - 1 Then
                e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentForeground)
                e.Graphics.DrawImage(IconImg, e.CellBounds)
                e.Handled = True
            End If
        End Sub
    

    if you have read full article for doing this check This link:

    http://www.authorcode.com/add-image-on-datagridview-column-header-in-vb-net/

提交回复
热议问题