ProcessKeyDown does not fire when TAB key is pressed

6 posts, 0 answers
  1. Jill-Connie Lorentsen
    Jill-Connie Lorentsen avatar
    118 posts
    Member since:
    Nov 2008

    Posted 12 Oct 2011 Link to this post

    In my custom ComboBoxEditorElement I override the ProcessKeyDown event so that when the user adds a value it is added to the DataSource. I want this to happen when the user presses Enter or the Tab key, but the event doesn't fire when the Tab key is pressed. Can anyone explain why, and hopefully give me a solution to the problem?

    public class MyComboBoxEditorElement : RadDropDownListEditorElement
            protected override void ProcessKeyDown(object sender, KeyEventArgs e)
                if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab)
                    List<string> dataSource = (List<string>)this.DataSource;                  
                    string name = this.Text;                  
                    if (!NameExists(name))
                        this.SelectedIndex = this.Items.Count - 1;                    
                        Update( dataSource[this.SelectedIndex].nameID, caseName);
                base.ProcessKeyDown(sender, e);
  2. Alexander
    Alexander avatar
    306 posts

    Posted 13 Oct 2011 Link to this post

    Hello Jill-Connie,

    Thank you for your question.

    The 'behavior' of RadGridView handles the Tab key and this is why it is not received in the ProcessKeyDown event of the editor element. You can create a custom 'behavior' for RadGridView and handle your case in its ProcessKey event:
    this.radGridView1.GridBehavior = new CustomGridBehavior();
    public class CustomGridBehavior : BaseGridBehavior
        public override bool ProcessKey(KeyEventArgs keys)
            if (keys.KeyCode == Keys.Tab || keys.KeyCode == Keys.Enter)
                // to access the editor of RadGridView use: this.GridControl.ActiveEditor
            return base.ProcessKey(keys);

    I hope will help you achieve your scenario.

    Best regards,
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. DevCraft R3 2016 release webinar banner
  4. Marco
    Marco avatar
    84 posts
    Member since:
    Apr 2011

    Posted 14 Dec 2015 Link to this post

    Hi Alexander,

    Thanks for you answer about the processing of TabKey on RadGridView. You save me some times.

    I will just add a word.

    After you have made your business with the editor, don't forget to return true instead of base.ProcessKey(keys) if you want the grid to stop the treatment of the event (moving to the next cell).

  5. Dess
    Dess avatar
    1561 posts

    Posted 14 Dec 2015 Link to this post

    Hello Marco,

    Thank you for writing.
    Indeed, it is necessary to return true if you need to stop further processing of the key. You can find additional information about row behaviors on the following link:

    I hope this information helps. Should you have further questions I would be glad to help.
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. حمید
    حمید avatar
    13 posts
    Member since:
    Dec 2015

    Posted 14 Oct in reply to Alexander Link to this post

    Hi Alexander

    I use  this senario   for  create editable RadComboBoxEditor. But I need to inheritance from two class !
    please see this code :

    01.namespace RadGridViewComboEditorCS
    04.    public class MyComboBoxEditor : RadDropDownListEditor
    05.    {
    06.        protected override RadElement CreateEditorElement()
    07.        {
    08.            return new MyComboBoxEditorElement();
    09.        }
    10.    }
    11.    public class MyComboBoxEditorElement :  RadDropDownListEditorElement
    12.    {
    14.        protected override void ProcessKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    15.        {
    16.            if ( e.KeyCode == Keys.Enter || e.KeyCode==Keys.Tab)
    17.            {
    18.                MessageBox.Show("yes");
    19.                BindingList<string> stringsDataSource = (BindingList<string>)this.DataSource;
    20.                string currentText = this.Text;
    22.                if (!ExistsInDataSource(currentText, stringsDataSource))
    23.                {
    24.                    stringsDataSource.Add(this.Text);
    25.                    this.SelectedIndex = this.Items.Count - 1;
    26.                    return;
    27.                }
    28.            }
    29.            base.ProcessKeyDown(sender, e);
    30.        }
    32.        private bool ExistsInDataSource(string currentText, BindingList<string> dataSource)
    33.        {
    34.            for (int i = 0; i < dataSource.Count; i++)
    35.            {
    36.                if (currentText == dataSource[i])
    37.                {
    38.                    return true;
    39.                }
    40.            }
    42.            return false;
    43.        }
    44.    }



    in your code 

    1.public class CustomGridBehavior : BaseGridBehavior


    so how can i inheritance from two class ( BaseGridBehavior and  RadDropDownListEditorElement ) ?


    BaseGridBehavior  :  for  keys.KeyCode == Keys.Tab 

    RadDropDownListEditorElement  for   create editable RadComboBoxEditor

    Thanks Telerik .


  7. Dess
    Dess avatar
    1561 posts

    Posted 3 days and 20 hours ago Link to this post


    Thank you for writing.  

    Note that BaseGridBehavior and RadDropDownListEditorElement are completely different classes purposed to handle completely different cases. While RadDropDownListEditorElement is used in the editor and it is designed to provide editing functionality, the BaseGridBehavior manages user mouse and keyboard input over its rows. Feel free to use the suggested approach by Alexander by creating a custom grid's editor and a custom row behavior in order to handle the desired scenarios. 
    I hope this information helps. Should you have further questions I would be glad to help.

    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
DevCraft R3 2016 release webinar banner