Hi there,
I have just upgraded my application to the latest version and discovered a weird bug with the GridView_CellFormatting event.
The previous version was trying to format the colors of the current cell depending on the value of another cell in the same row.
To simplify this behaviour, we can just look at 3 columns in a grid. Column 1: ID, Column 2: Name, Column 3: Status
If the status is True, Column 1's colour would be Blue and if the status is False, then column 1's colour would be Red.
in the previous version, the code was working fine..but with the new version, it seems that the Name column would also be affected.
and everytime the grid is refreshed through some random action e.g. moving of scrollbars, the name column's forecolor would change randomly..to either Red or Blue when those colours should only be affecting column 1.
P.s. I think The #2 example in http://www.telerik.com/help/winforms/formatting_cells.html is wrong... RowInfo.Cells[ColumnName] does not contain the CellElement property.
I have just upgraded my application to the latest version and discovered a weird bug with the GridView_CellFormatting event.
The previous version was trying to format the colors of the current cell depending on the value of another cell in the same row.
To simplify this behaviour, we can just look at 3 columns in a grid. Column 1: ID, Column 2: Name, Column 3: Status
If the status is True, Column 1's colour would be Blue and if the status is False, then column 1's colour would be Red.
in the previous version, the code was working fine..but with the new version, it seems that the Name column would also be affected.
and everytime the grid is refreshed through some random action e.g. moving of scrollbars, the name column's forecolor would change randomly..to either Red or Blue when those colours should only be affecting column 1.
private
void
gvDocuments_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement.RowIndex >= 0)
{
GridViewColumn col = e.CellElement.ColumnInfo
as
GridViewColumn;
GridViewRowInfo row = e.CellElement.RowInfo;
string
fieldName = col.Name;
if
(fieldName ==
"Id"
)
{
if
(row.Cells[
"Status"
].Value.ToString() ==
"T"
)
{
e.CellElement.ForeColor = Color.Blue;
e.CellElement.Font = font;
}
else
{
e.CellElement.ForeColor = Color.Red;
e.CellElement.Font = font;
}
}
}
}
P.s. I think The #2 example in http://www.telerik.com/help/winforms/formatting_cells.html is wrong... RowInfo.Cells[ColumnName] does not contain the CellElement property.
e.CellElement.RowInfo.Cells[
"column1"
].CellElement.ForeColor