'第0行第1列的背景色---红色 ,方法一 sGrid.Rows(0).Cells(1).Style .BackColor=Color.Red '第1行的背景色---红色 sGrid.Rows(1).DefaultCellStyle.BackColor = Color.Red方法二 If not sGrid.EditingControl Is Nothing Then '设置当前编辑列的背景色 sGrid.EditingControl.BackColor = Color.Red end if
不好意思,上次的代码错误,这次测试通过了,请楼主看看private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name.Equals("Sex")) { DataGridViewCell cell = dataGridView1[e.ColumnIndex, e.RowIndex]; String stringValue = e.Value as string; if (stringValue == null) { return; } switch (stringValue.Trim()) { case "女": e.CellStyle.BackColor = Color.Red; break; } } }
{
DataGridView1.Attributes.Add("style","BACKGROUND-COLOR: #99cc66"")
}
{
if (dataGridView1.Columns[e.ColumnIndex].Name.Equals("Sex"))
{
if (e.Value=="女")
{
e.CellStyle.BackColor =Color.Red;
}
}
}
根本就是乱讲。sz709("钱"途越渺茫...,越要拼命学...) (
你的方法不能实现目标呀,没能反应。
sGrid.Rows(0).Cells(1).Style .BackColor=Color.Red
'第1行的背景色---红色
sGrid.Rows(1).DefaultCellStyle.BackColor = Color.Red方法二
If not sGrid.EditingControl Is Nothing Then
'设置当前编辑列的背景色
sGrid.EditingControl.BackColor = Color.Red
end if
{
if (dataGridView1.Columns[e.ColumnIndex].Name.Equals("Sex"))
{
DataGridViewCell cell = dataGridView1[e.ColumnIndex, e.RowIndex];
String stringValue = e.Value as string;
if (stringValue == null)
{
return;
}
switch (stringValue.Trim())
{
case "女":
e.CellStyle.BackColor = Color.Red;
break;
}
}
}
{ if (GridView1.Rows[e].Cells[i].Text == "女")//如果每行的第i列值等于女就把这行变成红色色!
GridView1.Rows[e].BackColor = Color.Red;
}
看着这些答案都好笑