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

Focus issue when editing with text input

4 Answers 43 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 04 Oct 2011, 02:36 AM
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.

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 06 Oct 2011, 04:48 PM
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 >>

0
Brendan
Top achievements
Rank 1
answered on 07 Oct 2011, 01:31 AM
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)
            };
        }
    }
}

0
Maya
Telerik team
answered on 11 Oct 2011, 04:54 PM
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 >>

0
Brendan
Top achievements
Rank 1
answered on 22 Dec 2011, 02:50 AM
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.
Tags
GridView
Asked by
Brendan
Top achievements
Rank 1
Answers by
Maya
Telerik team
Brendan
Top achievements
Rank 1
Share this question
or