This is a migrated thread and some comments may be shown as answers.
Row highlight (mouse hover) event
2 Answers 161 Views
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 13 Jan 2010, 11:48 PM
Hello,
I'm looking for a way to register an event to the hover-over event of the GridView. Currently when you mouse over individual rows, it highlights them, but I wanted to extend this functionality so that when you mouse over a row, it fires an event so I can manipulate another control on the page based on which row is currently being moused-over.
How might I go about this?

2 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 14 Jan 2010, 11:40 AM
Hello Adam,

You can use our RowLoaded event to subscribe to the MouseEnter events of the grid rows and manipulate the other control when MouseEnter is raised. You could try something like this:

public MainPage()
{
    InitializeComponent();
  
    this.playersGrid.ItemsSource = Club.GetPlayers();
    this.playersGrid.RowLoaded += new System.EventHandler<RowLoadedEventArgs>(playersGrid_RowLoaded);
    this.playersGrid.RowUnloaded += new System.EventHandler<RowUnloadedEventArgs>(playersGrid_RowUnloaded);
}
  
void playersGrid_RowUnloaded(object sender, Telerik.Windows.Controls.GridView.RowUnloadedEventArgs e)
{
    var row = e.Row as GridViewRow;
  
    if (row != null)
    {
        row.MouseEnter -= new System.Windows.Input.MouseEventHandler(row_MouseEnter);
        row.MouseLeave -= new System.Windows.Input.MouseEventHandler(row_MouseLeave);
    }
}
  
void playersGrid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
    var row = e.Row as GridViewRow;
  
    if (row != null)
    {
        row.MouseEnter += new System.Windows.Input.MouseEventHandler(row_MouseEnter);
        row.MouseLeave += new System.Windows.Input.MouseEventHandler(row_MouseLeave);
    }
}
  
void row_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
    // restore other control
    var senderElement = e.OriginalSource as FrameworkElement;
    var mouseExitRow = senderElement.ParentOfType<GridViewRow>();
}
  
void row_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
    // change other control
    var senderElement = e.OriginalSource as FrameworkElement;
    var mouseOverRow = senderElement.ParentOfType<GridViewRow>();
}


Regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Adam
Top achievements
Rank 1
answered on 14 Jan 2010, 06:53 PM
Thanks for that elegant solution Milan.
It worked well, although I had to make a slight change to the row_MouseLeave method. I left is as:
 void row_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) 
 { 
     // restore other control 
     var mouseExitRow = e.OriginalSource as GridViewRowItem; 
      
 } 
When I used the one you posted,
void row_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) 
    // restore other control 
    var senderElement = e.OriginalSource as FrameworkElement; 
    var mouseExitRow = senderElement.ParentOfType<GridViewRow>(); 
mouseExitRow would come back as null (although the same method works fine for row_MouseEnter).

Anyways, thanks again for the help!




Asked by
Adam
Top achievements
Rank 1
Answers by
Milan
Telerik team
Adam
Top achievements
Rank 1
Share this question
or