Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:03:04+00:00 2026-05-11T07:03:04+00:00

I have a large DataGridView control that has several cells most of which contain

  • 0

I have a large DataGridView control that has several cells most of which contain a button. How can I change the color of those buttons?

This changes the ‘outline’ of the button but not the button itself.

row.Cells[2].Style.BackColor = System.Drawing.Color.Red; 

This doesn’t seem to change anything that’s visible:

row.Cells[2].Style.ForeColor = System.Drawing.Color.Red; 

If it’s not possible to change the background, is it possible to change the font on the button?

Using .NET 2.0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:03:05+00:00Added an answer on May 11, 2026 at 7:03 am

    As per MSDN:

    When visual styles are enabled, the buttons in a button column are painted using a ButtonRenderer, and cell styles specified through properties such as DefaultCellStyle have no effect.

    Therefore, you have one of two choices. In your Program.cs you can remove this line:

    Application.EnableVisualStyles(); 

    which will make it work, but make everything else look like crap. Your other option, and you’re not going to like this one, is to inherit from DataGridViewButtonCell and override the Paint() method. You can then use the static method on the ButtonRenderer class called DrawButton, to paint the button yourself. That means figuring out which state the cell currently is in (clicked, hover etc.) and painting the corners and borders etc… You get the idea, it’s doable, but a HUGE pain.

    If you want to though, here’s just some sample code to get you started:

     //Custom ButtonCell  public class MyButtonCell : DataGridViewButtonCell     {         protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)         {             ButtonRenderer.DrawButton(graphics, cellBounds, formattedValue.ToString(), new Font('Comic Sans MS', 9.0f, FontStyle.Bold), true, System.Windows.Forms.VisualStyles.PushButtonState.Default);         }     } 

    Then here’s a test DataGridView:

    DataGridViewButtonColumn c = new DataGridViewButtonColumn();             c.CellTemplate = new MyButtonColumn();             this.dataGridView1.Columns.Add(c);             this.dataGridView1.Rows.Add('Click Me'); 

    All this sample does, is paint a button with the font being ‘Comic Sans MS’. It doesn’t take into account the state of the button as you’ll see when you run the app.

    GOOD LUCK!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagridview that is horizontally large. A good portion of it must
I have large table (~1,000,000 rows) that may contain duplicates values. the table contain
I have an application which has a tabcontrol that contains two tabpages. I have
I have large string which I split by newlines. How can I remove all
i have large numbers of text files and i am in problem that i
I have large video files (~100GB) that are local on my machine. I have
I have large batches of XHTML files that are manually updated. During the review
I have large MQ patch applied in Mercurial. What has happened is I have
I have large text in System.Windows.Forms.TextBox control in my form (winforms), vs 2008. I
I have come accross a strange problem that can be illustrated using the 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.