Reputation: 1939
I'm on Telerik, & i'm trying to format a col values. The column index number 12
is already given a color(it works) and then I want to look for a particular value, if it's present then change the cell color. If the cell value is 4354 then change the cell color....but nothing is happening.
What is the mistake in below code???
private int cellValue = 4354;
for (int i = 0; i < TelerikRadGridView.Rows.Count; i++)
{
if (TelerikRadGridView.Rows[i].Cells[i].Value == (object)cellValue)
{
e.CellElement.BackColor = Color.Gold;
}
}
This is the complete code:
private int cellValue = 4354;
private void TelerikRadGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
if (dontRunHandler == false)
{
if (e.CellElement.ColumnIndex != 2
&& e.CellElement.ColumnIndex != 3
&& e.CellElement.ColumnIndex != 4
&& e.CellElement.ColumnIndex != 5
&& e.CellElement.ColumnIndex != 7
&& e.CellElement.ColumnIndex != 11
&& e.CellElement.ColumnIndex != 12
&& e.CellElement.ColumnIndex != 13) return;
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LightSlateGray;
e.CellElement.GradientStyle = GradientStyles.Linear;
}
for (int i = 0; i < TelerikRadGridView.Rows.Count; i++)
{
if (TelerikRadGridView.Rows[i].Cells[i].Value == (object)cellValue)
{
e.CellElement.BackColor = Color.Gold;
}
}
Upvotes: 2
Views: 1788
Reputation: 8598
Rewrote it for you so it would do what you want it to:
private int cellValue = 4354;
private void TelerikRadGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
if (dontRunHandler == false)
{
if (e.CellElement.ColumnIndex != 2
&& e.CellElement.ColumnIndex != 3
&& e.CellElement.ColumnIndex != 4
&& e.CellElement.ColumnIndex != 5
&& e.CellElement.ColumnIndex != 7
&& e.CellElement.ColumnIndex != 11
&& e.CellElement.ColumnIndex != 12
&& e.CellElement.ColumnIndex != 13) return;
else
{
if(e.CellElement.Value != null)
{
if (Double.Parse(e.CellElement.Value.ToString()) != cellValue)
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LightSlateGray;
e.CellElement.GradientStyle = GradientStyles.Linear;
}
else
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.Gold;
e.CellElement.GradientStyle = GradientStyles.Linear;
}
}
}
}
Upvotes: 2