PDA

View Full Version : آموزش: رنگی کردن ستون های دیتاگرید



NASA's Spaceman
چهارشنبه 21 خرداد 1393, 16:47 عصر
سلام
ابتدا یه دونه دیتاگرید روی صفحه گذاشته و کد زیر رو در رویداد فرم لود بنویسین
private void Form1_Load(object sender, EventArgs e) {
this.dataGridView1.Rows.Add(new object[] { 1,2,3});
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });
this.dataGridView1.Rows.Add(new object[] { 1, 2, 3 });


for (int counter = 0; counter < this.dataGridView1.Rows.Count; counter++)
{
if (counter % 2 == 0)
{
this.dataGridView1.Rows[counter].DefaultCellStyle.BackColor = Color.LightGray;
}
}
}
با سپاس Spaceman