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);
}
}
}
通過繼承原有的控件,直接實現交替顏色,也可以實現多行交替顏色。