Completed
Last Updated: 11 Oct 2023 08:02 by ADMIN
Release 6.3.0
Jamison
Created on: 25 Jul 2023 09:23
Category: DataGrid
Type: Bug Report
3
DataGrid: Views from a CellEditTemplate do not auto-focus upon entering edit mode

If I use the CellEditTemplate to show a custom view when editing - the view does not get auto focus when shown and the end user needs to tap inside so the view gets focus.

  <telerik:DataGridTextColumn PropertyName="CountryName" HeaderText="Country">
    <telerik:DataGridTextColumn.CellEditTemplate>
      <DataTemplate>
        <telerik:RadEntry Text="{Binding Item.CountryName}" />
      </DataTemplate>
    </telerik:DataGridTextColumn.CellEditTemplate>
  </telerik:DataGridTextColumn>

 

Work-around:

Manually invoke the Focus() method and set the cursor position when the view gets loaded and when it changes its visibility:

  <telerik:RadEntry Text="{Binding Item.CountryName}"
      Loaded="RadEntry_Loaded"
      PropertyChanged="RadEntry_PropertyChanged" />


private void RadEntry_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
  if (e.PropertyName == nameof(View.IsVisible))
  {
    RadEntry entry = (RadEntry)sender;
    if (entry.IsVisible)
    {
      FocusEntry(entry);
    }
  }
}

private void RadEntry_Loaded(object sender, EventArgs e)
{
  FocusEntry((RadEntry)sender);
}

private static void FocusEntry(RadEntry entry)
{
  entry.Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(1), () =>
  {
    entry.Focus();
    entry.CursorPosition = entry.Text?.Length ?? 0;
  });
}

 

0 comments