This is a migrated thread and some comments may be shown as answers.

Cell color not changing in Cell Validated Event Handler

0 Answers 64 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Karthik
Top achievements
Rank 1
Karthik asked on 22 Nov 2012, 07:09 PM
Hi Telerik, 
I got a Radgrid in my project, when i load the data i used Cell Formatting to give some colors by this way.


private void PrimaryRadGridView_CellFormatting(object sender, CellFormattingEventArgs e)
        {
 
            if (e.CellElement.ColumnInfo.FieldName == "ID")
            {
                e.CellElement.DrawFill = true;
                e.CellElement.NumberOfColors = 1;
                e.CellElement.BackColor = Color.LightSlateGray;
                e.CellElement.GradientStyle = GradientStyles.Linear;
            }
 
            if (e.CellElement.ColumnInfo.FieldName == "Type")
            {
                e.CellElement.DrawFill = true;
                e.CellElement.NumberOfColors = 1;
                e.CellElement.BackColor = Color.LightSlateGray;
                e.CellElement.GradientStyle = GradientStyles.Linear;
            }
            if (e.CellElement.ColumnInfo.FieldName == "BBor")
            {
                e.CellElement.DrawFill = true;
                e.CellElement.NumberOfColors = 1;
                //e.CellElement.ForeColor = Color.Red;
                e.CellElement.BackColor = Color.LightGoldenrodYellow;
                e.CellElement.GradientStyle = GradientStyles.Linear;
            }
            if (e.CellElement.ColumnInfo.FieldName == "EBor")
            {
                e.CellElement.DrawFill = true;
                e.CellElement.NumberOfColors = 1;
                e.CellElement.ForeColor = Color.Red;
                e.CellElement.BackColor = Color.LightGoldenrodYellow;
                e.CellElement.GradientStyle = GradientStyles.Linear;
            }
            if (e.CellElement.Value != null && e.CellElement.Value.ToString() == "PE0")
            {
                e.Row.Cells[4].ReadOnly = true;
                e.Row.Cells[4].Value = "XXXXXXXXXX";
                e.Row.Cells[4].Style.BackColor = Color.DarkRed;
                e.Row.Cells[4].Style.CustomizeFill = true;
            }
 
            
 
        }

Then I'm using to validate the cells and to change Fore & back color after the validation, but the color is not changing.
Cell Validated code:

private void PrimaryRadGridView_CellValidated(object sender, CellValidatedEventArgs e)
        {
 
 
            if (e.ColumnIndex != 3)
                return;
            if (e.RowIndex != -1)
            {
                int nextRowIndex = e.RowIndex + 1;
                int lastRowIndex = PrimaryRadGridView.Rows.Count - 1;
                if (nextRowIndex <= lastRowIndex)
                {
 
 
                    var value = PrimaryRadGridView.Rows[e.RowIndex].Cells[3].Value.ToString();
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[2].Value = value;
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[2].ReadOnly = true;
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[2].Style.ForeColor = Color.Blue;
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[2].Style.BackColor = Color.GreenYellow;
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[2].Style.CustomizeFill = true;
 
                    PrimaryRadGridView.ClearSelection();
 
                    PrimaryRadGridView.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect;
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[3].BeginEdit();
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[2].Style.ForeColor = Color.Blue;
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[3].Style.BackColor = Color.GreenYellow;
                    PrimaryRadGridView.Rows[nextRowIndex].Cells[3].Style.CustomizeFill = true;
 
 
                }
            }
             
        }

When i put a break point at both cell formatting & cell validated both are clashing each other. How ca i fix this  problem, please help me.

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Karthik
Top achievements
Rank 1
Share this question
or