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

ProcessKeyDown does not fire when TAB key is pressed

5 Answers 752 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jill-Connie Lorentsen
Top achievements
Rank 1
Jill-Connie Lorentsen asked on 12 Oct 2011, 10:39 AM
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))
                {                                  
                    AddToDataSource(name);
                    RefreshDataSource();
                    this.SelectedIndex = this.Items.Count - 1;                    
                }else
                {
                    Update( dataSource[this.SelectedIndex].nameID, caseName);
                    RefreshDataSource();
                }
            }
            base.ProcessKeyDown(sender, e);
        }

5 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 13 Oct 2011, 12:23 PM
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,
Alexander
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.

0
Marco
Top achievements
Rank 2
Veteran
answered on 14 Dec 2015, 03:19 PM

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).

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 14 Dec 2015, 03:41 PM
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: http://www.telerik.com/help/winforms/gridview-rows-row-behaviors.html

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
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
0
حمید
Top achievements
Rank 1
answered on 14 Oct 2016, 06:35 PM

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
02.{
03. 
04.    public class MyComboBoxEditor : RadDropDownListEditor
05.    {
06.        protected override RadElement CreateEditorElement()
07.        {
08.            return new MyComboBoxEditorElement();
09.        }
10.    }
11.    public class MyComboBoxEditorElement :  RadDropDownListEditorElement
12.    {
13.        
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;
21. 
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.        }
31. 
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.            }
41. 
42.            return false;
43.        }
44.    }
45.}

 

 

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 .

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Oct 2016, 06:29 AM
Hello,

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.

Regards,
Dess
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.
Tags
GridView
Asked by
Jill-Connie Lorentsen
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Marco
Top achievements
Rank 2
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
حمید
Top achievements
Rank 1
Share this question
or