This is a migrated thread and some comments may be shown as answers.

"F2" should not select all text

1 Answer 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 17 Apr 2019, 11:05 PM
Pressing F2 in a gridview/treelistview selects all of the text in the cell when it goes into edit mode. I am trying to make it work like Excel and just select the end of the text, but I can't see any way to do this. If I click in the cell to edit it, it the cursor goes where you click rather than selecting all.

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 22 Apr 2019, 07:25 AM
Hello Steve,

The gridview API doesn't allow changing this behavior. However, you can achieve your requirement by creating a custom column and override its PrepareCellForEdit method. There you can get the TextBox control and de-select its text. Here is an example in code:
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>

I've also attached a small example showing this approach. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or