0

我可以更改 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)
        { }
    }

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

        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)
        { }
    }
4

2 回答 2

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?
    }
于 2013-03-21T06:27:48.077 回答
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为这个特殊的工作处理事件。结果将如下所示: 在此处输入图像描述

编辑

仅设置一个单元格的颜色 - 处理事件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;
}
于 2013-03-21T06:44:23.747 回答