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

How to change the GridViewHeaderCellElement Mouse hover Color

2 Answers 193 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rangadurai
Top achievements
Rank 1
Rangadurai asked on 15 Sep 2012, 11:57 AM
Hi,

How to change the GridViewHeaderCellElement Mouse hover Color through code Instead of using style builder. Please help on this very urgent.

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 17 Sep 2012, 12:55 PM
Hi Rangadurai,

Thank you for writing.

Here is how using the MouseMove and the ViewCellFormatting event, you can achieve the desired functionality:
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement is GridHeaderCellElement && e.CellElement.Tag != null && e.CellElement.Tag == "IamHoveredCell")
        {
            e.CellElement.BackColor = Color.Red;
            e.CellElement.GradientStyle = GradientStyles.Solid;
            e.CellElement.DrawFill = true;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        }
    }
    GridHeaderCellElement lastHoveredCell;
    void radGridView1_MouseMove(object sender, MouseEventArgs e)
    {
        if (lastHoveredCell != null)
        {
            lastHoveredCell.Tag = null;
            lastHoveredCell.UpdateInfo();
        }
 
        GridHeaderCellElement cellElement = radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
        if (cellElement != null)
        {
 
 
            cellElement.Tag = "IamHoveredCell";
            lastHoveredCell = cellElement;
            cellElement.UpdateInfo();
        }
    }

More information regarding the formatting abilities of RadGridView can be found here: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html.

I hope this helps. 

All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Rangadurai
Top achievements
Rank 1
answered on 17 Sep 2012, 04:12 PM
Hi Stefan,

Thanks for your support.
your suggestion works like charm.
Tags
GridView
Asked by
Rangadurai
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Rangadurai
Top achievements
Rank 1
Share this question
or