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