New to Telerik UI for WPF? Download free 30-day trial

Mouse Support

RadGridView exposes several useful events, which can help you control the mouse interaction and get notified when mouse events occur. Moreover, using the mouse you can perform some most common tasks, such as:

  • Change the selection.

  • Sort by clicking on the column headers.

  • Group by one or more columns.

  • Expand\Collapse groups or hierarchical grids.

  • Resize and reorder columns.

  • Freeze\Unfreeze columns.

  • Define\Remove simple filters.

  • Start\End cell editing.

Events

Here is a list of the common mouse events exposed by RadGridView, GridViewRow and GridViewCell objects:

  • MouseWheel - occurs when the user rotates the mouse wheel. The type of the passed event arguments is MouseWheelEventArgs.

  • MouseMove - occurs when the coordinate position of the mouse changes. The type of the passed event arguments is MouseEventArgs.

  • MouseLeftButtonDown - occurs when the left mouse button is pressed. The type of the passed event arguments is MouseButtonEventArgs.

  • MouseLeftButtonUp - occurs when the left mouse button is released. The type of the passed event arguments is MouseButtonEventArgs.

  • MouseLeave - occurs when the mouse leaves the control. The type of the passed event arguments is MouseEventArgs.

  • MouseEnter - occurs when the mouse enters the control. The type of the passed event arguments is MouseEventArgs.

  • LostMouseCapture - occurs when the object loses mouse capture. The type of the passed event arguments is MouseEventArgs.

  • MouseDoubleClick - occurs when the grid view cell is double clicked by the user. The type of the passed event arguments is MouseButtonEventArgs. Note that this event is available only in the GridViewCell object.

In the example below you can see how to attach to MouseWheel event from XAML.

<telerik:RadGridView x:Name="radGridView" MouseWheel="radGridView_MouseWheel" /> 

It is always a good practice to attach your event handlers in the XAML, whenever your application logic allows this.

The implementation of the event handler radGridView_MouseWheel is located in the code-behind file (C# or VB.NET) and looks like this:

private void radGridView_MouseWheel(object sender, MouseWheelEventArgs e) 
{ 
    MessageBox.Show("The mouse wheel has changed: " + e.Delta); 
} 
Private Sub radGridView_MouseWheel(ByVal sender As Object, ByVal e As MouseWheelEventArgs) 
    MessageBox.Show("The mouse wheel has changed: " & e.Delta) 
End Sub 

The RadGridView actually uses and handles many of the mouse events. If you would like to handle them yourself, you should use the AddHandler() method of the GridView and set True for the HandledEventsToo input parameter.

this.radGridView.AddHandler(RadGridView.MouseWheelEvent, new MouseWheelEventHandler(radGridView_MouseWheel), true); 
Me.radGridView.AddHandler(RadGridView.MouseWheelEvent, New MouseWheelEventHandler(AddressOf radGridView_MouseWheel), True) 

See Also

In this article