Group Header Key Intercept

3 posts, 1 answers
  1. Ryan
    Ryan avatar
    2 posts
    Member since:
    Jan 2013

    Posted 04 Jan 2013 Link to this post

    Using: SL5 with Telerik controls v2012.2.912.1050

    I'm attempting to use a RadGridView to present a fully interactive edit window honoring specific grouping elements.  The caveat is that the group headers are also editable.  The template for the header looks like so:
    <Telerik:RadGridView.GroupHeaderTemplate>

        <DataTemplate>
            <TextBox Text="{Binding Path=Header, Mode=TwoWay}"
                     DataContext
    ="{Binding Path=Group.Key}"
                    
    MaxLength="1000" />
        </DataTemplate>
    </telerik:RadGridView.GroupHeaderTemplate>

    The problem posed is that when editing the Header value, I cannot use the space character.  It seems that the group header is intercepting the key stroke and not allowing it to tunnel down to the text box.  The effect of presssing space in this textbox is a toggling of the visibility of the group's children.  Do you have any suggestions to remedy this behavior so that the Textbox takes prescedence on input?

    Thanks,
    -Ryan

  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 04 Jan 2013 Link to this post

    Hi Ryan,

    I can suggest you to add handler to the KeyDown event of the page and perform some additional logic there:

    private void TextBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Space)
        {
            var tb = sender as TextBox;
            if (tb != null)
            {
                int selStart = tb.SelectionStart;
                tb.Text = tb.Text.Insert(tb.SelectionStart, " ");
                tb.SelectionStart = selStart + 1; //put the caret back in the right place
                e.Handled = true;
            }
        }
    }

    That way the TextBox will accept the "Space". Please let me know how this works for you.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Ryan
    Ryan avatar
    2 posts
    Member since:
    Jan 2013

    Posted 04 Jan 2013 Link to this post

    This works perfectly.  Thank you.
Back to Top