为DataGrid中的第一行设置背景颜色? [英] Set background color only for the first row in a DataGrid?
本文介绍了为DataGrid中的第一行设置背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为c#中smartDevice项目中的DataGrid的第一个颜色更改颜色。
我试图使用油漆事件,但无法弄清楚是否可以解决我的问题。
我使用的是Microsoft Visual Studio 2008。
这是一个测试代码
private void buttonRed_Click(object sender,EventArgs e)
{
DataRow row = this.dataSet1.Tables [0] .NewRow();
row [0] =002;
row [1] =E;
this.dataSet1.Tables [0] .Rows.InsertAt(row,0);
}
private void load()
{
this.dataSet1.Tables [0] .Rows.Add(new object [] {001,一个 });
this.dataSet1.Tables [0] .Rows.Add(new object [] {002,B});
this.dataSet1.Tables [0] .Rows.Add(new object [] {001,C});
this.dataSet1.Tables [0] .Rows.Add(new object [] {003,D});
}
private void buttonGreen_Click(object sender,EventArgs e)
{
DataRow row = this.dataSet1.Tables [0] .NewRow();
row [0] =004;
row [1] =F;
this.dataSet1.Tables [0] .Rows.InsertAt(row,0);
}
解决方案
dataGridView1.Rows [0] .DefaultCellStyle.BackColor = Color.Azure;
只要这样做就可以...
0表示第一行。 >
I'm trying to change the color only for the first color of a DataGrid in a smartDevice project in c#. I tried to use the "Paint" event but couldn't figure out if it could solve my issue. I'm using Microsoft Visual Studio 2008.
This is a testing code
private void buttonRed_Click(object sender, EventArgs e)
{
DataRow row = this.dataSet1.Tables[0].NewRow();
row[0] = "002";
row[1] = "E";
this.dataSet1.Tables[0].Rows.InsertAt(row, 0);
}
private void load()
{
this.dataSet1.Tables[0].Rows.Add(new object[] { "001", "A" });
this.dataSet1.Tables[0].Rows.Add(new object[] { "002", "B" });
this.dataSet1.Tables[0].Rows.Add(new object[] { "001", "C" });
this.dataSet1.Tables[0].Rows.Add(new object[] { "003", "D" });
}
private void buttonGreen_Click(object sender, EventArgs e)
{
DataRow row = this.dataSet1.Tables[0].NewRow();
row[0] = "004";
row[1] = "F";
this.dataSet1.Tables[0].Rows.InsertAt(row, 0);
}
解决方案
dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Azure;
Just do this will work... 0 means the first row.
这篇关于为DataGrid中的第一行设置背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文