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

Prevent GridView Column Resize on Mouse Double-Click

Environment

Product Version 2022.2 621
Product RadGridView for WPF

Description

RadGridView column resizes, when a double-click is performed between the header cells.

Solution

  1. Add a new event handler for the PreviewMouseDoubleClick event of the GridViewHeaderCell element via the AddHandler method.

Add a new event handler for the PreviewMouseDoubleClick of the GridViewHeaderCell element

this.AddHandler(GridViewHeaderCell.PreviewMouseDoubleClickEvent, new MouseButtonEventHandler(OnPreviewMouseDoubleClick)); 
Me.AddHandler(GridViewHeaderCell.PreviewMouseDoubleClickEvent, New MouseButtonEventHandler(OnPreviewMouseDoubleClick)) 
  1. In the new event handler, set the e.Handled property to true, if the e.OriginalSource is of typeBorder.

Prevent the PreviewMouseDoubleClick event from bubbling if the OriginalSource is of type Border

private void OnPreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) 
{ 
    if (e.OriginalSource is Border) 
    { 
        e.Handled = true; 
    }  
} 
Private Sub OnPreviewMouseDoubleClick(ByVal sender As Object, ByVal e As MouseButtonEventArgs) 
    If TypeOf e.OriginalSource Is Border Then 
        e.Handled = True 
    End If 
End Sub 
In this article