Click here to Skip to main content
11,806,923 members (60,007 online)
Click here to Skip to main content

Set Image as Background for DataGridView

, 14 Feb 2007 CPOL 59.8K 49
Rate this:
Please Sign up or sign in to vote.
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

You may also be interested in...

Comments and Discussions

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
helitb28-Mar-07 3:06
memberhelitb28-Mar-07 3:06 
GeneralNice work! Here's how to get the rest of the image Pin
Patrick Sears15-Feb-07 17:55
memberPatrick Sears15-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    Rant Rant    Admin Admin   

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151002.1 | Last Updated 14 Feb 2007
Article Copyright 2007 by ELhajjNet
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid