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

Programmatically set hovered row

3 Answers 209 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roman
Top achievements
Rank 1
Roman asked on 03 Aug 2016, 11:29 AM

Hello,

I have standard control drag and drop in my app, so I have .net DragEnter, DragDrop, DragOver, etc. handlers for the RadGridView in my form. Of course, grid doesn't react properly on mouse activity over it. In my DragOver handler I want to set row under the cursor to hovered state. I found GridTableElement.HoveredRow property, but it is internal. Is there a way to programmatically make grid to set a row into howered state?

3 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Aug 2016, 12:31 PM
Hello Roman,

Thank you for writing. 

In order to highlight the target cell, you can handle the RadGridView.DragOver, get the cell element under the mouse and customize its look:
GridCellElement lastCell = null;
 
private void radGridView1_DragOver(object sender, DragEventArgs e)
{
    if (lastCell != null)
    {
        lastCell.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        lastCell.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        lastCell.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
    }
    Point p = this.radGridView1.PointToClient(new Point(e.X,e.Y));
    lastCell = this.radGridView1.ElementTree.GetElementAtPoint(p)as GridCellElement ;
    if (lastCell != null)
    {
        lastCell.DrawFill = true;
        lastCell.BackColor = Color.LightCyan;
        lastCell.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
    }
}

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Roman
Top achievements
Rank 1
answered on 03 Aug 2016, 01:09 PM

Hello Dess,

Well, this is just a workaround, because the tracking will not be the same as the normal one. I need to highlight full row, so I changed your example from cells to rows. But row header is not highlighted and there is no triangle icon on it. In case the row is selected, changing all these properties messed up the things, because current cell remains selected but the rest of the row becomes just highlighted.

But as you've provided a workaround, that means there is no defined way to do that I need. So I guess I have to live with this approach. But I would ask you to think about making GridTableElement.HoveredRow a public property (or something similar). :)

Thank you

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Aug 2016, 11:34 AM
Hello Roman 

Thank you for writing back. 

I am glad that the suggested solution is applicable for your case. Note that changing the color for the hovered element in the DragOver event is a standard approach for achieving such a requirement. There are a lot of threads related to this topic in stackOverflow. Here is one of them: http://stackoverflow.com/questions/8146705/how-to-highlight-target-node-while-dragging

As to the question about the GridTableElement.HoveredRow property, note that it is designed for internal usage as it is responsible for the hot tracking state of a row element which is used in the themes. 

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Roman
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Roman
Top achievements
Rank 1
Share this question
or