sinat_33460472
哆啦CMeng
2018-05-21 01:43
采纳率: 39.1%
浏览 894
已采纳

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条回答 默认 最新

  • dabocaiqq
    dabocaiqq 2018-05-21 01:51
    已采纳

    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);

    }

    }

    }

    点赞 评论
  • softboy99
    softboy99 2018-05-21 06:18

    应该用RowCellStyle事件不是RowStyle

    点赞 评论

相关推荐