Focus issue when editing with text input

5 posts, 0 answers
  1. Brendan
    Brendan avatar
    34 posts
    Member since:
    Oct 2010

    Posted 03 Oct 2011 Link to this post

    I think I found an issue with the 2011.2.927.1040 hotfix.

    I am using a grid view with custom column types inherited from GridViewBoundColumnBase. I have a custom editing control which contains an editable RadComboBox and a TextBox. Everything was working ok unitl I upgraded to the hot fix to fix a different issue.

    When I type, the cell goes into edit mode as it should. Previously when editing focus was given to the RadComboBox (being the first editable control) and the text entered there, however now it skips the combobox and gives focus to the textbox instead.

    Please let me know if you manage to fix this, thanks.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Oct 2011 Link to this post

    Hello Brendan,

    Could you share a bit more details about the exact implementation of your column ? Generally, any relevant information or code-snippet would be helpful.
     

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Brendan
    Brendan avatar
    34 posts
    Member since:
    Oct 2010

    Posted 06 Oct 2011 Link to this post

    I have reproduced the issue in a small sample project.

    EditControl.xaml
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="120" />
        </Grid.ColumnDefinitions>
     
        <TextBlock Grid.Row="0" Grid.Column="0" Text="Value" VerticalAlignment="Center" />
        <TextBlock Grid.Row="1" Grid.Column="0" Text="Override" VerticalAlignment="Center" Margin="0,5,0,0" />
        <TextBlock Grid.Row="2" Grid.Column="0" Text="Comment" VerticalAlignment="Center" Margin="0,5,0,0" />
     
        <telerik:RadComboBox Grid.Row="0" Grid.Column="1" IsEditable="True" Margin="5,0,0,0" IsTabStop="True" TabIndex="0" />
        <TextBox Grid.Row="1" Grid.Column="1" Margin="5,5,0,0" TabIndex="1" />
        <TextBox Grid.Row="2" Grid.Column="1" Margin="5,5,0,0" TabIndex="2" />
     </Grid>

    EditControl.xaml.cs
    public partial class EditControl : UserControl
    {
        public EditControl()
        {
            InitializeComponent();
        }
     
        public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register("Value", typeof(int), typeof(EditControl), new PropertyMetadata(0));
     
        public int Value
        {
            get { return (int)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }
    }

    GridEditColumn.cs
    public class GridEditColumn : GridViewBoundColumnBase
    {
        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
        {
            Binding binding = new Binding(DataMemberBinding.Path.Path);
     
            EditControl control = new EditControl();
            control.SetBinding(EditControl.ValueProperty, binding);
     
            return control;
        }
    }

    MainPage.xaml
    <Grid>
        <telerik:RadGridView x:Name="DataGrid" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Row}" />
                <local:GridEditColumn DataMemberBinding="{Binding Value}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>

    MainPage.xaml.cs

    public class Data
    {
        public int Row { get; set; }
        public int Value { get; set; }
    }
     
    public partial class MainPage : UserControl
    {
        private Random _rand = new Random();
     
        public MainPage()
        {
            InitializeComponent();
     
            DataGrid.ItemsSource = GenerateData();
        }
     
        private IEnumerable<Data> GenerateData()
        {
            for (int i = 0; i < 100; ++i)
            {
                yield return new Data()
                {
                    Row = i,
                    Value = _rand.Next(400, 450)
                };
            }
        }
    }

  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Oct 2011 Link to this post

    Hi Brendan,

    Indeed, you are quite correct - I managed to reproduce the issue with the code-snippets provided. Still we will need some more time to investigate the cause of the problem. For the time being as a workaround I could suggest you to handle PreparedCellForEdit event of RadGridView as follows:

    private void DataGrid_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
            {
                if (e.Column.DisplayIndex == 1)
                {
                    (e.EditingElement as FrameworkElement).ChildrenOfType<RadComboBox>().FirstOrDefault().Focus();
                }
            }
     

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. Brendan
    Brendan avatar
    34 posts
    Member since:
    Oct 2010

    Posted 21 Dec 2011 Link to this post

    Hello firstly I'd like to say thankyou for the help. My original issue above was fixed quite fast in the next update, however there is still one problem which after updating still exists within the 2011 Q3 SP1 release.

    Using the code I supplied above if I make the RadComboBox in the EditControl.cs disabled or read-only and edit the grid by inputting text into a cell, it puts the first character into the disabled combobox. This also happens if a textbox or any other editable control is used instead of a combobox.

    I would instead expect it to give focus to the next editable control.
Back to Top