-
Apr 28th, 2019, 11:32 PM
#1
Thread Starter
Lively Member
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?
-
Apr 29th, 2019, 12:12 AM
#2
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.
-
Apr 29th, 2019, 12:59 AM
#3
Thread Starter
Lively Member
Re: How do I make the BG color of my DataGridView WHITE?
Originally Posted by jmcilhinney
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.
-
Apr 29th, 2019, 01:17 AM
#4
Re: How do I make the BG color of my DataGridView WHITE?
Originally Posted by Volkof
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.
-
Apr 29th, 2019, 01:35 AM
#5
Thread Starter
Lively Member
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.
-
Apr 29th, 2019, 02:12 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|