How to display an image in a datagridview column header?

前端 未结 4 560
傲寒
傲寒 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:25

    Try This:

    Private Sub DataGridView1_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
            If e.RowIndex > -1 Then
    
                If e.ColumnIndex = -1 Then
                    e.Paint(e.CellBounds, DataGridViewPaintParts.Focus And Not DataGridViewPaintParts.ContentForeground)
                    DataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
                    e.Graphics.DrawImage(IconImg, e.CellBounds)
                    e.Handled = True
                    'DataGridView1.RowHeadersWidth = 100
                    'DataGridView1.ColumnHeadersHeight = 25
                End If
    
            End If
    

提交回复
热议问题