Click here to Skip to main content
14,875,113 members
Articles / Programming Languages / Visual Basic
Posted 14 Feb 2007


51 bookmarked

Set Image as Background for DataGridView

Rate me:
Please Sign up or sign in to vote.
3.39/5 (10 votes)
14 Feb 2007CPOL
How to show an image in the background for DataGridView
Sample image


I needed to set an image as the background of DataGridView. I searched the Internet but could not find anything useful, so I did it myself. It is easy and small; I have tested it and it is working ok. Before you use it, please test it.

How To Do It

Just create a new class and inherit it from DataGridView as follows:

Imports system.ComponentModel

Public Class usrDataGridView
    Inherits Windows.Forms.DataGridView

    Private m_Image As Drawing.Image

    Public Sub New()
        Me.m_Image = Drawing.Image.FromFile("c:\sisnetBG.jpg")
    End Sub

    Protected Overrides Sub PaintBackground(_
        ByVal graphics As System.Drawing.Graphics, _
        ByVal clipBounds As System.Drawing.Rectangle, _
        ByVal gridBounds As System.Drawing.Rectangle)
        MyBase.PaintBackground(graphics, clipBounds, gridBounds)

        graphics.DrawImage(Me.m_Image, gridBounds)

    End Sub

    <description("set /> _
    Public Property BackImage() As Drawing.Image
            Return Me.m_Image
        End Get
        Set(ByVal value As Drawing.Image)
            Me.m_Image = value
        End Set
    End Property

End Class


  • 14th February, 2007 -- Original version posted


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Lebanon Lebanon
No Biography provided

Comments and Discussions

Questiononly on the bottom right corner Pin
rojaldearintok14-Nov-15 6:15
Memberrojaldearintok14-Nov-15 6:15 
QuestionHow to apply it to the Form??? Pin
mhc200425-Aug-09 22:16
Membermhc200425-Aug-09 22:16 
QuestionHow to apply it to my form Pin
jugnoginting4-Jul-09 0:48
Memberjugnoginting4-Jul-09 0:48 
GeneralScroll Error Pin
Arash Javadi26-Apr-09 12:41
MemberArash Javadi26-Apr-09 12:41 
GeneralA couple of additions Pin
Snixtor5-Nov-08 11:35
MemberSnixtor5-Nov-08 11:35 
GeneralI need Source please Pin
Elmurhaf4-Jul-08 11:14
MemberElmurhaf4-Jul-08 11:14 
GeneralAbove Column Headers Pin
harunmip28-Mar-07 3:06
Memberharunmip28-Mar-07 3:06 
GeneralNice work! Here's how to get the rest of the image Pin
Patrick Etc.15-Feb-07 17:55
MemberPatrick Etc.15-Feb-07 17:55 
GeneralRe: Nice work! Here's how to get the rest of the image Pin
ELhajjNet16-Feb-07 10:46
MemberELhajjNet16-Feb-07 10:46 
GeneralRe: Nice work! Here's how to get the rest of the image Pin
Yazeed Hamdan2-Jun-15 6:48
MemberYazeed Hamdan2-Jun-15 6:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.