Click here to Skip to main content
15,886,766 members
Please Sign up or sign in to vote.
3.80/5 (3 votes)
See more:
I have created one Form with DataGridView control and have changed DataGridView control's grid colour to black.
I want to set other Grid colour to only RowHeader.

How to do it?
Please Help.
Posted
Updated 3-Mar-11 21:45pm
v4
Comments
OriginalGriff 4-Mar-11 2:20am    
Sorry, but that doesn't make a lot of sense.
Could you try explaining in more detail what you are trying to achieve?
It may be worth your using short words in you native language, and translating via Google Translate.
Please edit your question and give more information!
Prasad131 4-Mar-11 2:25am    
How to set differnt colours to Datagridview Cell grids and Datagridview RowHeader's Grid....?
Dalek Dave 4-Mar-11 3:46am    
Edited for Readability.

Ah! That makes a bit more sense!
Set an individual Cell colour:
C#
myDataGridView[col, row].Style.BackColor = Color.Red;

To set the header background colour:
C#
myDataGridView.EnableHeadersVisualStyles = false;
myDataGridView.Columns[col].HeaderCell.Style.BackColor = Color.Green;
Setting EnableHeadersVisualStyles to false will cause other changes which you will have to override manually - you will see what I mean when you set it - it's up to you whether it is worth the effort! Basically, in order to change the colour, you have to take display control away and do it all yourself...
 
Share this answer
 
Comments
Prasad131 4-Mar-11 3:45am    
Thank You So Much...!
But I am asking about Grid Color.
You have given the solution for BackColor.

I want to set Black color to Cell's Grid
and Red Color to RowHeader's Grid.

Please Do Reply !
Dalek Dave 4-Mar-11 3:46am    
Good Call
Hope this[^] might help you.
 
Share this answer
 
Comments
Prasad131 4-Mar-11 2:10am    
Thanks for Help...!
But I am playing with DataGridView in Windows Application.
Can u plz help me in that concern...?
Dalek Dave 4-Mar-11 3:47am    
Don't see why you are getting down voted, I think OP is new.
Compensated for your time and effort.
[no name] 4-Mar-11 3:48am    
Thanks Dalek.
Hope this[^] might help you.
 
Share this answer
 
Comments
Dalek Dave 4-Mar-11 3:47am    
Don't see why you are getting down voted, I think OP is new.
Compensated for your time and effort.
[no name] 4-Mar-11 3:48am    
Thanks Dalek.
Hello

Try this:

this.dataGridView1.EnableHeadersVisualStyles = false;

DataGridViewTextBoxColumn col5 = new DataGridViewTextBoxColumn();
col5.DefaultCellStyle.BackColor = Color.Yellow; col5.HeaderCell.Style.Font = new Font("Arial", 8, FontStyle.Bold);
col5.HeaderCell.Style.BackColor = Color.Yellow;
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900