Click here to Skip to main content
Click here to Skip to main content

Set Image as Background for DataGridView

By , 14 Feb 2007
Rate this:
Please Sign up or sign in to vote.
Sample image

Introduction

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
        Get
            Return Me.m_Image
        End Get
        Set(ByVal value As Drawing.Image)
            Me.m_Image = value
        End Set
    End Property

End Class

History

  • 14th February, 2007 -- Original version posted

License

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

About the Author

ELhajjNet

Lebanon Lebanon
No Biography provided

Comments and Discussions

 
QuestionHow to apply it to the Form??? Pinmembermhc200425-Aug-09 22:16 
QuestionHow to apply it to my form Pinmemberjugnoginting4-Jul-09 0:48 
GeneralScroll Error PinmemberArash Javadi26-Apr-09 12:41 
GeneralA couple of additions PinmemberSnixtor5-Nov-08 11:35 
GeneralI need Source please PinmemberElmurhaf4-Jul-08 11:14 
GeneralAbove Column Headers Pinmemberhelitb28-Mar-07 3:06 
GeneralNice work! Here's how to get the rest of the image PinmemberPatrick Sears15-Feb-07 17:55 
GeneralRe: Nice work! Here's how to get the rest of the image PinmemberELhajjNet16-Feb-07 10:46 

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 | Mobile
Web03 | 2.8.140415.2 | Last Updated 14 Feb 2007
Article Copyright 2007 by ELhajjNet
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid