日期:2014-05-19  浏览次数:20889 次

DataGrid颜色设置
大家帮忙说一下!!!
如何设置DataGrid中列的颜色和行的颜色!!!

------解决方案--------------------
private void ColFormat()
{
for(int i = 0; i < dtgaut2.Items.Count; i++)
{
//给标题和偶数列初始化颜色15267071
dtgaut2.HeaderStyle.BackColor = Color.FromArgb(15267071);
if(i % 2 != 0)
{
dtgaut2.Items[i].BackColor = Color.FromArgb(15267071);
}
------解决方案--------------------
DataGridView设置颜色

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
int i;
for (i = 0; i < this.dataGridView1.Rows.Count; i++)
{
if (i % 2 == 0)
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.MintCream;
}
else
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.LightYellow;
}
}
}