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

F2 Should not Select All Text in RadGridView Cell

Environment

Product Version 2019.1 415
Product RadGridView for WPF

Description

How to disable the text selection when a cell enters edit mode by pressing the F2 key.

Solution

  1. Create a custom RadGridView column and override its PrepareCellForEdit method.
  2. In the method override, get the editing element (TextBox) and manually set its SelectionStart property.

public class CustomGridViewDataColumn : GridViewDataColumn 
{ 
    protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) 
    { 
        var cell = base.PrepareCellForEdit(editingElement, editingEventArgs); 
        var tb = editingElement as TextBox; 
        if (tb != null && !(editingEventArgs is MouseButtonEventArgs)) 
        { 
            tb.SelectionStart = tb.Text.Length; 
        } 
        return cell; 
    } 
} 

<telerik:RadGridView.Columns> 
    <local:CustomGridViewDataColumn DataMemberBinding="{Binding Name}" /> 
</telerik:RadGridView.Columns> 

See Also

In this article