Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2008

Tip: Looking for answers? Try searching our database.

how to give DataGridViewButtonColumn a background image

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lamis - 09 Jan 2008 09:15 GMT
Hi
this is my code
DataGridViewButtonColumn buttonupColumn =
               new DataGridViewButtonColumn();
           buttonupColumn.HeaderText = "";
           buttonupColumn.Name = "btnUp";
           buttonupColumn.Text = "Up";
I want to have a background image to my button instear of the .text ="Up"

Any idea how to do that??
Signature

LZ

Morten Wennevik [C# MVP] - 09 Jan 2008 16:08 GMT
Hi Lamis,

You can use the DataGridView.CellPainting event to add custom drawing to any
cell.  Set the DataGridViewCellPaintingEventArgs.Handled property to prevent
the custom drawing to be erased.

This code will add a magenta rectangle on top of any column called "Button",
in this case this happens to be a DataGridViewButtonColumn.

       protected override void OnLoad(EventArgs e)
       {
           DataGridViewButtonColumn bc = new DataGridViewButtonColumn();
           bc.Name = "Button";
           dataGridView1.Columns.Add(bc);
           dataGridView1.CellPainting += new
DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
       }

       void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
       {
           if (e.ColumnIndex == -1 || e.RowIndex == -1)
               return;

           if (dataGridView1.Columns[e.ColumnIndex].Name == "Button")
           {
               e.Paint(e.CellBounds, DataGridViewPaintParts.All);
               e.Graphics.FillRectangle(Brushes.Magenta, e.CellBounds.Left
+ 10, e.CellBounds.Top + 5, 10, 10);
               e.Handled = true;
           }
       }

Signature

Happy Coding!
Morten Wennevik [C# MVP]

> Hi
> this is my code
[quoted text clipped - 6 lines]
>
> Any idea how to do that??

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.