Question Add an image next to the Text in DataGridview Column Header

azmg5

New member
Joined
Oct 19, 2008
Messages
2
Programming Experience
3-5
Hello,

I want to add an image next to the text in the DataGridview column Header without removing the arrow image that is displayed when the column is sorted, but i don't know how. Can anyone help me please?
 
Last edited:
VB.NET:
	Private Sub DataGridView1_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) _
	Handles DataGridView1.CellPainting

		If e.ColumnIndex = 1 AndAlso e.RowIndex = -1 Then
			e.PaintBackground(e.ClipBounds, False)

			Dim pt As Point = e.CellBounds.Location
			Dim offset As Integer = (e.CellBounds.Width - Me.ImageList1.ImageSize.Width) / 2

			pt.X += offset
			pt.Y = 1
			Me.ImageList1.Draw(e.Graphics, pt, 0)

			e.Handled = True

		End If

	End Sub
 
Back
Top