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

Change cell BackColor but retain its hover color

1 Answer 117 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tamás
Top achievements
Rank 1
Tamás asked on 26 Aug 2008, 07:30 AM
Hi,

I changed the BackColor property of a CellElement using the CellFormatting event, but it seems very awkward compared to the other cells in the row when that row is hovered or selected:
the other cells in the row change their colors because of the hovering, whereas the cell whose BackColor I adjusted remains the same.

How can I help this poor cell to behave like its fellows?

Thanks,
Tamás

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 28 Aug 2008, 02:52 PM
Hello Tamás,

Thank you for writing.

To avoid changing the visual settings you have to check if the cell in CellFormating event is from Current or Selected row. Please review the code-block below as example:
 
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) 
    if (e.CellElement.ColumnIndex == 2 && e.CellElement is GridDataCellElement) 
    { 
         
        GridDataCellElement cell = e.CellElement as GridDataCellElement; 
        if (cell.RowInfo != this.radGridView1.CurrentRow && !cell.IsSelected && 
            cell.Value.ToString() == "4"
        { 
            cell.DrawFill = true
            cell.BackColor = Color.Red; 
            cell.ForeColor = Color.White; 
        } 
        else 
        { 
            cell.DrawFill = false
            cell.BackColor = Color.White; 
            cell.ForeColor = Color.Black; 
        } 
    } 

I hope this helps.
 

Best wishes,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Tamás
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or