Hi
How to change Default TAB Key to ENTER Key, It's urgent Requirement, How Would be possible.
I want to use this Code, But how to fire event, Please Help me.
private void SelectNextControl(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Return:
this.SelectNextControl(this.ActiveControl,true,true,true,true);
break;
//case Keys.<some key>:
// …;
// break;
}
Thanks
We have closed this ticket because another page addresses its subject:
Layout - How to switch between the Tab and Enter keys to focus controls on a Windows FormHow to set focus by the Enter key
Answers
Hello,
Lookup editors and grid handle the Enter key. This explains the fact that an event is not fired. You can inherit the DetailViewForm template and override its ProcessDialogKey method to handle the Enter key. Below is some sample code (add a new module to our previous sample project).
C#using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Templates;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Win.Templates;
namespace WinSolution.Module.Win {
public class MyDetailViewForm : DetailViewForm {
private Control GetActiveControl(ContainerControl containerControl) {
Control result = containerControl.ActiveControl;
if((result != null) && (result is ContainerControl)) {
result = GetActiveControl((ContainerControl)result);
}
return result;
}
protected override bool ProcessDialogKey(Keys keyData) {
Keys keyCode = keyData & Keys.KeyCode;
if((keyCode == Keys.Return) && ((keyData & Keys.Modifiers) == Keys.None)) {
Control activeControl = GetActiveControl(this);
if(activeControl != null) {
return SelectNextControl(activeControl, true, true, true, true);
}
}
return base.ProcessDialogKey(keyData);
}
public MyDetailViewForm() : base() { }
}
}
Then override the OnCreateCustomTemplate method of the WinSolutionWindowsFormsApplication class defined in the WinApplication.cs unit:
C#using System;
using System.Collections.Generic;
using System.ComponentModel;
using DevExpress.ExpressApp.Win;
using DevExpress.ExpressApp.Templates;
using DevExpress.ExpressApp;
using WinSolution.Module.Win;
namespace WinSolution.Win {
public partial class WinSolutionWindowsFormsApplication : WinApplication {
...
protected override IFrameTemplate OnCreateCustomTemplate(string name) {
if(name == TemplateContext.View) {
return new MyDetailViewForm();
}
return base.OnCreateCustomTemplate(name);
}
}
}
Finally, you can remove the layout.OptionsFocus.EnableAutoTabOrder = false; line from the ViewController1 class. After that the Enter moves focus to the last control on your form. By improving the ProcessDialogKey method, you can implement circular tabbing through controls, if needed.
Thanks,
Nick
@Sergey: Please post your non-working sample project in a separate ticket. We will be glad to research it.
Hello Dennis,
This solution works fine in detailviews for most editors. But unfortunately it does'nt work for a MemoEdit.
Do you have a solution for this problem?
Thanks.
@Vekrasoft: Certain complex editors like a lookup, date time, image and memo handle the Enter key internally. You may need to create a descendant of the underlying control to handle this scenario, e.g. as described at T151540.
In your particular case, you can adjust the RepositoryItemMemoEdit.AcceptsReturn Property. If this does not help, please create a separate Support Center ticket and attach your test sample so we can debug and research your situation further.
Hi Hemant,
Thank you for the update.
I have found a solution for you. Please test the attached WinForms application. You can also implement this functionality in an XAF application using a view controller.
Please let me know if you have any difficulty.
Thanks,
Dennis
Hi Hemant,
Sorry for the delay in responding. Please see the attached sample project. It works fine for me. Did this help you?
Thank you for your patience,
Dennis
Hello,
I apologize for the delay. These days we've been a little bit overloaded with support queries.
We are working on your issue, and will answer ASAP.
Thanks,
Dennis