Question regarding CellFormatting
I have just bought a couple of licenses of radcontrols. And I must say; I am very impressed! It helps me save loads of time.
I have a radgrid filled with data (like this):
Name Bit (should be hidden) Phone
John 1 22445566
Mike 0 44556677
Joan 1 44556677
And I want to change the background-color on Name-cell if Bit is set to 1. The background color for the cell with John and Joan should be yellow. And Mike should stay as it is.
This is normally functionality that I would solve using the OnItemDataBound-event. But now I guess I have to use the CellFormatting-event instead.
I figured out that I could not grab the value of Bit, because the column is hidden (radgridDialog.Columns["myBitField"].IsVisible = false;)
So then I tried to prefix my name-column from my stored procedure. So John and Joan became <pre>John and <pre>Joan. Not the nicest solution I have seen. But I was starting to get desperate. Do anyone have an better idea?
The logic almost work. The only thing I'm having problems with now is to change the value of the cell. My function looks like this:
|void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)|
|// exclude header element in the data column|
|if (e.CellElement.ColumnInfo is GridViewDataColumn && !(e.CellElement.RowElement is GridHeaderRowElement))|
|GridViewDataColumn column = (GridViewDataColumn)e.CellElement.ColumnInfo;|
|if (column.DataField == "Name")|
|Font font = e.CellElement.Font;|
|//What should the line below be? I see that e.CellElement.Value is readonly|
|//e.CellElement.SetValue(Telerik.WinControls.RadProperty rd, (object)e.CellElement.Value.ToString().Replace("<pre>", ""));|
|e.CellElement.Font = font;|
|e.CellElement.BackColor = Color.Yellow;|
|e.CellElement.ForeColor = Color.Tomato;|