Results 1 to 2 of 2

Thread: Add an image next to the Text in DataGridview Column Header

  1. #1
    azmg5 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    2
    Reputation
    0

    Add an image next to the Text in DataGridview Column Header

    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 by azmg5; 10-19-2008 at 8:55 AM.

  2. #2
    MattP is offline VB.NET Forum All-Mighty
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2008
    Location
    WY, USA
    Posts
    1,206
    Reputation
    618
    Code:
    	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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •