using
System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Costaco.CTN.Controls
... {
public class DataGridView : System.Windows.Forms.DataGridView
...{
public DataGridView()
...{
}
//这里键入override,然后空格就会出来重写的列表,你选一个回车就可以了写出不同的override
protected override void OnDataBindingComplete(DataGridViewBindingCompleteEventArgs e)
...{
if (this.Rows.Count != 0)
...{
for (int i = 0; i < this.Rows.Count; i++)
...{
if ((i % 2) == 1)
...{
this.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke;
}
else
...{
this.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue;
}
}
}
base.OnDataBindingComplete(e);
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Costaco.CTN.Controls
... {
public class DataGridView : System.Windows.Forms.DataGridView
...{
public DataGridView()
...{
}
//这里键入override,然后空格就会出来重写的列表,你选一个回车就可以了写出不同的override
protected override void OnDataBindingComplete(DataGridViewBindingCompleteEventArgs e)
...{
if (this.Rows.Count != 0)
...{
for (int i = 0; i < this.Rows.Count; i++)
...{
if ((i % 2) == 1)
...{
this.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke;
}
else
...{
this.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue;
}
}
}
base.OnDataBindingComplete(e);
}
}
}
通过继承原有的控件,直接实现交替颜色,也可以实现多行交替颜色。