Is it possible to set color on a specific column in a DataGridView

T

Tony Johansson

Hello!

This DataGridView is connected to the DataTable.
I just wonder if it's possible to set a color on a specific column.
I have a column that is autoincrement and I want this DataColumn to have a
specific color.

//Tony
 
S

Stanimir Stoyanov \(C# MVP\)

Hi Tony,

If you have the DataTable bound to the DataGridView at design time, you can
do this by invoking the "Edit Columns..." task on the control, selecting the
column and editing its DefaultCellStyle. The designer will let you choose a
BackColor for the column.

Alternative, you can do it in code by instantiating a new
DataGridViewCellStyle class, setting the desired BackColor property and
updating your DataGridViewColumn with the cell style.
 
S

Stanimir Stoyanov \(C# MVP\)

Hi Tony,

If you have the DataTable bound to the DataGridView at design time, you can
do this by invoking the "Edit Columns..." task on the control, selecting the
column and editing its DefaultCellStyle. The designer will let you choose a
BackColor for the column.

Alternative, you can do it in code by instantiating a new
DataGridViewCellStyle class, setting the desired BackColor property and
updating your DataGridViewColumn with the cell style.
 
T

Tim Roberts

Tony Johansson said:
Can you give a simple example how this is done.

Google is your friend, and it is much faster then waiting for a newsgroup
response.
 
T

Tim Roberts

Tony Johansson said:
Can you give a simple example how this is done.

Google is your friend, and it is much faster then waiting for a newsgroup
response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top