How to interleave 2 colors in rows of the DataGridView DevExpress? In C # .Net

0

I used the RowStyle event with the following code:

private void dgvPersonalizadoInterior_RowStyle(object sender, RowStyleEventArgs e)
        {
            try
            {
                for (int i = 0; i < dgvPersonalizadoInterior.RowCount; i++)
                {
                    if ((i % 2) == 0)
                        e.Appearance.BackColor = Color.Red;
                    else
                        e.Appearance.BackColor = Color.LightYellow;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

I was looking for information on the subject, but I did not find anything.

Do you have any ideas?

    
asked by Nahuel Picca 09.06.2017 в 17:29
source

3 answers

3

If I did not understand correctly, what you are looking for is a row of one color and the next of another, as well as the entire list you have on the grid.

If what I understood is correct, you can do it through the designer.

Try the following:

1.- Run Designer of the GridControl
2.- You select the GridView
3.- Search the Property Appearance
4.- Within Appearance there is EvenRow and OddRow with specific properties to style these rows.

It's already a matter of assigning the style you're most looking for.

    
answered by 09.06.2017 / 18:39
source
0

Thank you very much for the information.

Although to be able to visualize the colors intercalated in the grid it is necessary to activate this:

GridView1.OptionsView.EnableAppearanceEvenRow = true;
GridView1.OptionsView.EnableAppearanceOddRow = true;
    
answered by 12.06.2017 в 14:43
0

You can use the HtmlDataCellPrepared property For example, I have two columns that I compare and modify the color of those that have different quantities.

    settings.HtmlDataCellPrepared = (sender, e) =>
            {
                if (e.DataColumn.FieldName == "decProdsPedidos" || e.DataColumn.FieldName == "decProdsSurtidos")
                {
                    decimal decProdsPedidos = Convert.ToDecimal(e.GetValue("decProdsPedidos"));
                    decimal decProdsSurtidos = Convert.ToDecimal(e.GetValue("decProdsSurtidos"));
                    if (decProdsPedidos != decProdsSurtidos)
                    {
                        e.Cell.BackColor = System.Drawing.Color.GreenYellow;
                        e.Cell.Enabled = false;
                    }
                }       
            };
    
answered by 04.07.2017 в 22:29