在EditorRow中更改文本颜色

时间:2013-03-20 14:51:57

标签: c# colors devexpress

我可以为VGridControl中的所有记录更改颜色。

vGridControl1.Appearance.ReadOnlyRecordValue.ForeColor

但我不知道如何仅为一行改变颜色。

EditorRow row = new EditorRow(id);
row.Name = "row" + id;
row.Properties.Row.Appearance.ForeColor = ColorText;
row.Properties.Row.Appearance.Options.UseForeColor = true;

我尝试做点什么。但它不起作用。 请帮帮我。

好吧,如果我使用事件CustomDrawRowHeaderCell,我可以改变标题的颜色。代码:

private void vGridControl1_CustomDrawRowHeaderCell(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawRowHeaderCellEventArgs e)
    {
        try {
            System.Drawing.Color ColorText = Color.FromArgb(m_Color.r, m_Color.g, m_Color.b);
            e.Row.Appearance.ForeColor = ColorText;
        }
        catch (Exception ex)
        { }
    }

但是,当我尝试更改文本行颜色时,我遇到了问题:我无法更改文本行颜色。但我可以更改BackColor行。谁能帮我? 代码:

        private void vGridControl1_CustomDrawRowValueCell(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawRowValueCellEventArgs e)
    {
        try
        {
            System.Drawing.Color ColorText = Color.FromArgb(m_Color.r, m_Color.g, m_Color.b);
            e.Row.Appearance.ForeColor = ColorText;
            e.Row.Appearance.Options.UseForeColor = true;
            e.Row.Appearance.BackColor = ColorText;
        }
        catch (Exception ex)
        { }
    }

2 个答案:

答案 0 :(得分:0)

在这里,我在VGridControl中插入Row。 我可以在此功能中更改文字颜色吗?

enter code here


 private void InsertNewRow(string id, string text, int type)
    {
        EditorRow row = new EditorRow(id);
        row.Name = "row" + id;
        row.Properties.ImageIndex = type;
        //vGridControl1.Appearance.ReadOnlyRecordValue.ForeColor = ColorText;
        M_Objects myColorObject = new M_Objects();
        if (GetObjectById(id, ref myColorObject) >= 0)
        {
            m_Color = myColorObject.Color;
        }
        System.Drawing.Color ColorText = Color.FromArgb(m_Color.r, m_Color.g, m_Color.b);
        row.Appearance.ForeColor = ColorText;//here I try to change color
        row.Appearance.Options.UseForeColor = true;//It does not work

        if (vGridControl1.RepositoryItems.Count == 0)
            vGridControl1.RepositoryItems.Add("TextEdit");
        row.Properties.RowEdit = vGridControl1.RepositoryItems[0];
        row.Properties.Value = text;


        row.Height = 28;
        row.Properties.ReadOnly = true;
        vGridControl1.Rows["MainRow"].ChildRows.Add(row);//I don't write this code. Is it right?
    }

答案 1 :(得分:0)

我建议您去看看gridview上的DevExpress文档。

如果你需要一行来改变颜色,你可以这样做:

  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();

      gridControl1.DataSource = new List<Structure>
        {
          new Structure {Id = 1, Val1 = "nr 1"}, 
          new Structure {Id = 2, Val1 = "nr 2"}, 
          new Structure {Id = 3, Val1 = "nr 3"}
        };
    }

    private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
    {
       int myExpectedRowHandle = 1;
       if (e.RowHandle == myExpectedRowHandle)
       {
         e.Appearance.BackColor = Color.Crimson;
       }
    }
  }

  public class Structure
  {
    public string Val1 { get; set; }
    public int Id { get; set; }
  }

您处理此特定工作的RowStyle事件。 结果会像这样: enter image description here

修改

设置一个单元格的颜色 - 处理事件RowCellStyle

在我的考试中你会看起来像这样:

private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
  int myExpectedRowHandle = 1;
  if (e.Column != colVal1 || e.RowHandle != myExpectedRowHandle)
    return;

  e.Appearance.ForeColor = Color.Crimson;
}