0

I used the Grid in the Telerik samples for WinUI C:\Program Files (x86)\Telerik\UI for WinForms Q1 2015\Examples\QuickStart\GridView\Rows\AddNewRow\Form1.cs and added the following code to get the UnitPrice in a blue font:

 public Form1()
    {
       ...
        this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);
    }

        void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridDataCellElement dataCell = e.CellElement as GridDataCellElement;
        if (dataCell != null)
        {
            if (dataCell.ColumnInfo.Name.ToLower() == "unitprice")
            {
                dataCell.ForeColor = System.Drawing.Color.Blue;
                dataCell.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
            }
        }
    }

This works when the form get first loaded:

enter image description here

If I scroll the form vertically some of the other columns get blue too. Is there something I can do about this?

enter image description here

Dean Chalk
  • 20,076
  • 6
  • 59
  • 90
Mathias F
  • 15,906
  • 22
  • 89
  • 159

2 Answers2

1

Customization should be reset for other columns

 if (dataCell.ColumnInfo.Name.ToLower() == "unitprice")
        {
            dataCell.ForeColor = System.Drawing.Color.Blue;
            dataCell.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
        }

else
{
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
}
Mathias F
  • 15,906
  • 22
  • 89
  • 159
0

Try this in Cell Formatting, changed the if condition

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
   if (e.CellElement.ColumnInfo.Name == "unitprice")
   {
    dataCell.ForeColor = System.Drawing.Color.Blue;
    dataCell.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
   }
}
Balaji
  • 1,375
  • 1
  • 16
  • 30