I have a custom Editor derived from BaseInputEditor based on a RadButtonTextBoxElement.
In the "EndEdit()" function I change another property of the selected object, how can I see if the user canceled the edit by pressing ESC, so I can prevent the change of the other property?
2 Answers, 1 is accepted
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Dec 2020, 06:49 AM
Hello, Andreas,
RadPropertyGrid handles pressing the Escape key in its ProcessDialogKey method:
There is no dedicated event for handling when the edit operation is rejected by pressing the Escape key. You can create a derivative of RadPropertyGrid and override its ProcessDialogKey method to detect the specific key.
An alternative approach is to handle the keyboard input in the activated editor. Here is demonstrated a sample code snippet:
publicRadForm1()
{
InitializeComponent();
this.radPropertyGrid1.SelectedObject = this;
this.radPropertyGrid1.EditorInitialized+=radPropertyGrid1_EditorInitialized;
}
privatevoidradPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
{
PropertyGridTextBoxEditor textBoxEditor = e.Editor as PropertyGridTextBoxEditor;
if (textBoxEditor!=null)
{
BaseTextBoxEditorElement el = textBoxEditor.EditorElement as BaseTextBoxEditorElement;
el.TextBoxItem.TextBoxControl.PreviewKeyDown+=TextBoxControl_PreviewKeyDown;
}
}
privatevoidTextBoxControl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyData== Keys.Escape)
{
Console.WriteLine("Escape");
}
}
Feel free to use this approach which suits your custom requirements best.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thanks, this is solves my problem. I was using the KeyDown event to try the same result, but there the Escape Key is already filtered out, the PreviewKeyDown event is working!