Doğan Etkin
Doğan Etkin

Reputation: 77

Couldn't change the telerik radgrid cell background color

I want to change a cell's background color on a telerik radgrid on windows form project if the incoming value is "Var" but couldn't manage to do it.

private void radGridView1_DataBindingComplete(object sender, Telerik.WinControls.UI.GridViewBindingCompleteEventArgs e)
{
    for (int i = 0; i < radGridView1.RowCount; i++)
    {
        string ImageStatusButton = radGridView1.Rows[i].Cells[7].Value.ToString();

        if (ImageStatusButton == "Var")
            radGridView1.Rows[i].Cells[7].Style.BackColor = Color.Red;
    }
}

note: i am able to change the forecolor but couldn't change the backcolor.

Upvotes: 1

Views: 3868

Answers (1)

Stanley David
Stanley David

Reputation: 21

Try to digest my code below. It works!

Dim colIndex = FloorZoningGridView.Columns("colSizeInPercent").Index
            Dim cellPlaceHolder As Telerik.WinControls.UI.GridCellElement

            If currentFloorZoningProperty.GetFloorZoningTotalSizePercent <> 100 Then
                For Each row In FloorZoningGridView.Rows
                    cellPlaceHolder = FloorZoningGridView.TableElement.GetCellElement(row, FloorZoningGridView.Columns(colIndex))


                    cellPlaceHolder.DrawFill = True
                    cellPlaceHolder.BackColor = Drawing.Color.Pink

                Next

            Else
                For Each row In FloorZoningGridView.Rows
                    cellPlaceHolder = FloorZoningGridView.TableElement.GetCellElement(row, FloorZoningGridView.Columns(colIndex))


                    cellPlaceHolder.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local) 
                    cellPlaceHolder.ResetValue(VisualElement.BackColorProperty, ValueResetFlags.Local) 

                Next

            End If

Upvotes: 2

Related Questions