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
- Add a new event handler for the
PreviewMouseDoubleClick
event of theGridViewHeaderCell
element via theAddHandler
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))
- In the new event handler, set the
e.Handled
property totrue
, if thee.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