dev 表格字体变色问题

我设置的当点击停用按钮的时候,表格字体变成红色,可是当每次点击某行表格获图片说明得焦点的时候,改行字体颜色又变成黑色,离开后,又变成红色,求大神帮助

#region 为行加删除线
private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
int hand = e.RowHandle;
if (hand < 0) return;
DataRow dr = this.gridView1.GetDataRow(hand);
if (dr== null) return;
if (dr["FYXMIFQY"].ToString().Equals("1"))
{
e.Appearance.ForeColor = Color.Red;// 改变行字体颜色
//e.Appearance.BackColor = Color.Red;// 改变行背景颜色
//e.Appearance.BackColor2 = Color.Blue;// 添加渐变颜色
//……
//根据需求
//e.Appearance.Font.Strikeout = true;
}
else
{
e.Appearance.ForeColor = Color.Black;// 改变行字体颜色
}
}
#endregion

2个回答

1.拖一个gridControl控件在 窗体上

2.添加三列 分别是 BgColor,BgColor2 , FontColor 分别显示单元格颜色 单元格渐变颜色 单元格字体颜色

[csharp] view plain copy
public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

List list = new List();

list.Add(new { BgColor = 11, BgColor2 = 12, FontColor = 13 });

list.Add(new { BgColor = 21, BgColor2 = 22, FontColor = 23 });

list.Add(new { BgColor = 31, BgColor2 = 32, FontColor = 33 });

gridControl1.DataSource = list;

}

private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)

{

GridView View = sender as GridView;

if (e.Column.FieldName == "BgColor")//设背景

{

//int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;

e.Appearance.BackColor = Color.Red;

}

else if (e.Column.FieldName == "BgColor2")//设渐变背景

{

//int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;

e.Appearance.BackColor = Color.Red;

e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);

}

else if (e.Column.FieldName == "FontColor")//设字体颜色

{

//int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;

e.Appearance.ForeColor = Color.Red;//Color.FromArgb(42, 173, 231);

}

}

}

sinat_33460472
哆啦CMeng 十分感谢
2 年多之前 回复

应该用RowCellStyle事件不是RowStyle

sinat_33460472
哆啦CMeng 十分感谢!
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问