读书人

怎样设置dataGridview的背景颜色?该如

发布时间: 2012-01-07 21:41:55 作者: rapoo

怎样设置dataGridview的背景颜色???
在Winform开发中...

我想设置datagridview的背景颜色.........

我要是datagridview 所有的奇数行为一中颜色,,偶数行为另外一种颜色//


谢谢了

[解决办法]
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
if (i % 2 == 0)
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
else
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Green;
}
}
[解决办法]
直接设置datagridview属性:AlternatingRowsDefaultCellStyle
[解决办法]
一个属性可以让dataGridView实现奇数行为一种颜色,偶数行为另外一种颜色??怎么设?
[解决办法]
奇数行采用AlternatingRowsDefaultCellStyle属性。
偶数行采用DefaultCellStyle属性。
[解决办法]
RowStyle AlternatingRowsDefaultCellStyle
里的backcolor设的不同就可以了,或者直接在 autoformat里选一个就行了
[解决办法]
RowStyle AlternatingRowsDefaultCellStyle
里的backcolor设的不同就可以了,或者直接在 autoformat里选一个就行了
-----------------------------------------
copy 错了, 是AlternatingRowsStyle和 RowStyle

[解决办法]
protected virtual void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.Value == null) return;

foreach (DataGridViewColumn d in this.dataGridView.Columns) //为克服 DataGridView BUG (只刷新可见字段部份)
{
if (d.Name.IndexOf( "IsStop ") != -1)
{
if (this.dataGridView.Rows[e.RowIndex].Cells[d.Index].Value.ToString() == "是 ")
this.dataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Coral;
}
if (d.Name.IndexOf( "IsDefault ") != -1)
{
if (this.dataGridView.Rows[e.RowIndex].Cells[d.Index].Value.ToString() == "是 ")
this.dataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.YellowGreen;
}
if (d.Name.IndexOf( "IsCurrent ") != -1)
{
if (this.dataGridView.Rows[e.RowIndex].Cells[d.Index].Value.ToString() == "是 ")
this.dataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.BlueViolet;
}
}
}

读书人网 >C#

热点推荐