本文介绍了在 DevExpress GridView 上更改行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 devexpress 网格视图中将行的颜色更改为绿色.在搜索时,我发现了许多如何执行此操作的示例...在网站中,但这是一个 Windows 应用程序.我在 Windows 应用程序上找不到任何东西,所以有人可以在这里帮我一下.

I am trying to change the colour of a row to green in a devexpress gridview. When searching I found many examples of how to do this... in websites BUT this is a windows application. I cannot find any thing on a windows application so can someone please help me out a bit here.

我只是想将单行的颜色更改为绿色.

I simply just want to change the colour of a single row to green.

忘了说,它是一个 C# 应用程序.

Forgot to mention, its a C# application.

感谢您的帮助.

推荐答案

用于在运行时更改行颜色处理 RowStyle 事件:

For changing the row colour in runtime handle the RowStyle event:

    public Color color1;
    public Color color2;
    public int rowhandle;

    private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
    {
        try
        {
            if (e.RowHandle == rowhandle)
            {
                if (color1 != null && color2 != null)
                {
                    e.Appearance.BackColor = color1;
                    e.Appearance.BackColor2 = color2;
                }
            }
        }
        catch
        {
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        color1 = Color.BurlyWood;
        color2 = Color.DarkOrchid;
        rowhandle = gridView1.FocusedRowHandle;
        gridView1.RefreshRow(rowhandle);
    }

下面的代码将保持颜色:

The code bellow will maintain the colour:

public partial class Form1 : Form
{

    public Color color1;
    public Color color2;
    public int rowhandle;
    public List<int> rowhandles;

    private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
    {
        try
        {
            if (rowhandles.Any(x=>x==e.RowHandle))
            {
                if (color1 != null && color2 != null)
                {
                    e.Appearance.BackColor = color1;
                    e.Appearance.BackColor2 = color2;
                }
            }
        }
        catch
        {
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        color1 = Color.BurlyWood;
        color2 = Color.DarkOrchid;
        rowhandle = gridView1.FocusedRowHandle;
        if (!rowhandles.Any(x => x == rowhandle))
            rowhandles.Add(rowhandle);
        gridView1.RefreshRow(rowhandle);
    }

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Dictionary<int, string> l = new Dictionary<int, string>();
        l.Add(1,"one");
        l.Add(2,"two");
        l.Add(3,"three");
        l.Add(4, "four");
        l.Add(5, "five");
        l.Add(6, "six");
        l.Add(7, "seven");
        l.Add(8, "eight");
        l.Add(9, "nine");

        gridControl1.DataSource = l.ToList();

        rowhandles = new List<int>();
    }

}

这篇关于在 DevExpress GridView 上更改行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 02:29