winformDataGridView设置选中单元格整⾏变⾊和隔⾏变⾊
//设置⽹格颜⾊
List<Student> stu = new List<Student>();
Student s1 = new Student();
s1.Name = "⼩明";
s1.age = 23;
stu.Add(s1);
Student s2 = new Student();
s2.Name = "⽼张";
s2.age = 21;
stu.Add(s2);
Student s11 = new Student();
s11.Name = "⼩李";
s11.age = 30;
stu.Add(s11);
Student s22 = new Student();
s22.Name = "云峰";
s22.age = 20;
stu.Add(s22);
Student s111 = new Student();
s111.Name = "⼩明";
s111.age = 23;
stu.Add(s111);
Student s222 = new Student();
s222.Name = "⽼张";
s222.age = 21;
stu.Add(s222);
Student s1111 = new Student();
s1111.Name = "⼩李";
s1111.age = 30;
stu.Add(s1111);
Student s2222 = new Student();
s2222.Name = "云峰";
s2222.age = 20;
stu.Add(s2222);
//绑定数据源
datagridview数据源dataGridView1.DataSource = stu;
//选中单元格整⾏变⾊
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置整⾏变⾊
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Yellow;//设置背景⾊
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.LightBlue;//设置前景⾊
//设置隔⾏换⾊
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (i % 2 == 0)
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论