Re: Setting the BackColor of indvidual cells in a DataGridView
- From: "RobinS" <RobinS@xxxxxxxxxxxxxxx>
- Date: Fri, 9 Feb 2007 16:56:14 -0800
You have to do it through the DefaultCellStyle property.
DataGridViewCellStyle MakeItRed = new DataGridViewCellStyle;
MakeItRed.BackColor = Color.Red;
//make a whole column red
myGrid.Columns(1).DefaultCellStyle = MakeItRed;
//make a specific cell red
DataGridViewRow row2 = myGrid.Rows(2);
row2.Cells(2).Style = MakeItRed
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"Paul" <heythereto@xxxxxxxx> wrote in message
news:1171053144.786378.252760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello All,
I have been trying to figure out how to set the BackColor of
individual cells in a DataGridView. I found the following solution in
a VB usenet group
DataGridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Color
DataGridView1.Item(ColumnIndex, RowIndex).Style.ForeColor = Color
or
DataGridView1.CurrentCell.Style.BackColor = Color
DataGridView1.CurrentCell.Style.ForeColor = Color
I figured I could just change the () to [] and it would work in C#.
Howver, the DataGridView does not seem to have an Item property. How
can I accomplish this using C#?
Thanks,
Paul
.
- Follow-Ups:
- References:
- Prev by Date: How to restore corrupted user.config file
- Next by Date: Re: string to byte[] back to string + Compression Failed!
- Previous by thread: Re: Setting the BackColor of indvidual cells in a DataGridView
- Next by thread: Re: Setting the BackColor of indvidual cells in a DataGridView
- Index(es):