Ticket Q182351
Visible to All Users
Duplicate

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 Form

How to set focus by the Enter key

created 17 years ago

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

Comments (3)
Dennis Garavsky (DevExpress) 17 years ago

    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

    Dennis Garavsky (DevExpress) 17 years ago

      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

      Dennis Garavsky (DevExpress) 17 years ago

        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

        Answers

        created 17 years ago

        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

          Show previous comments (2)
          Dennis Garavsky (DevExpress) 12 years ago

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

              Dennis Garavsky (DevExpress) 10 years ago

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

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.