Results 1 to 6 of 6

Thread: How do I make the BG color of my DataGridView WHITE?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    How do I make the BG color of my DataGridView WHITE?

    This sound a bit silly, but how do I make the BG color of my DataGridView WHITE?

    Right now they are Grey.

    I tried changing DataGridView Properties, BackgroundColor and GridColor to WHITE, but still doesn't work

    Can this be done without coding?

    Name:  Make BG White.jpg
Views: 340
Size:  36.1 KB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How do I make the BG color of my DataGridView WHITE?

    It's a nested property you need. The DefaultCellStyle property of the grid is type DataGridViewCellStyle. That class is used in various places to set various style-related properties of cells and, in this case, it is the default style for every cell in the grid. The BackColor property of that type determines the BackColor of affected cells. In this case, it's set to SystemColors.Window by default so, if you're seeing grey, either you must have already set the property or else your system theme uses grey for windows. You can change it in the designer via the properties window and a dialogue, or you can change it in code. If you do it in code, I think that it will only affect cells created after the change.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Re: How do I make the BG color of my DataGridView WHITE?

    Quote Originally Posted by jmcilhinney View Post
    It's a nested property you need. The DefaultCellStyle property of the grid is type DataGridViewCellStyle. That class is used in various places to set various style-related properties of cells and, in this case, it is the default style for every cell in the grid. The BackColor property of that type determines the BackColor of affected cells. In this case, it's set to SystemColors.Window by default so, if you're seeing grey, either you must have already set the property or else your system theme uses grey for windows. You can change it in the designer via the properties window and a dialogue, or you can change it in code. If you do it in code, I think that it will only affect cells created after the change.

    Ok, so if I understand correctly, you are saying the color is inherited?
    And I need to go to the SystemColors.Window to change?
    Can I just do this in the VB editor?

    If really need to code, I guess it's fine.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How do I make the BG color of my DataGridView WHITE?

    Quote Originally Posted by Volkof View Post
    Ok, so if I understand correctly, you are saying the color is inherited?
    And I need to go to the SystemColors.Window to change?
    Apparently you don't understand. Maybe start by actually looking at the value of the property I told you was responsible for that colour. If that is indeed set to SystemColors.Window then it is the default value and the actual colour is coming from your system theme. If you want to change the system theme then that's done via the system, so nothing to do with VB or VS. If you want to change the property value to something other than what it is currently, go ahead and change it.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Re: How do I make the BG color of my DataGridView WHITE?

    It's ok, I found the issue.

    I have this and commented it out:

    Code:
    Private Sub ProjectsDataGridView_CellFormatting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles ProjectsDataGridView.CellFormatting
    Last edited by Volkof; Apr 29th, 2019 at 01:52 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How do I make the BG color of my DataGridView WHITE?

    As I mentioned, the DataGridViewCellStyle class is used in various places. The DefaultCellStyle property is the top level and it can be overridden at various other levels, including the column, row and cell. In the CellFormatting event handler, the e.CellStyle property is, yet again, type DataGridViewCellStyle and is close to the last level at which you can change the style for a cell, i.e. as it is being formatted for rendering. You can still override that style when it gets rendered too.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width