日期:2014-05-17 浏览次数:20959 次
private void UserControl1_Load(object sender, EventArgs e)
{
DataTable dt=new DataTable();
dt.Columns.Add("test");
for (int i = 0; i < 6; i++)
{
DataRow dataRow=dt.NewRow();
dataRow["test"] = "test";
dt.Rows.Add(dataRow);
}
dataGridView1.DataSource = dt;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (i % 2 == 0)
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
else
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.RoyalBlue;
}
}
}
dataGridView1.RowsDefaultCellStyle.BackColor = Color.Red;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.RoyalBlue;