Problem with ProcessKeyDialog

9 posts, 0 answers
  1. Trinh
    Trinh avatar
    10 posts
    Member since:
    Dec 2010

    Posted 11 May 2011 Link to this post

    Hi, I have a customer form with these information: Customer ID, Customer Name, Customer Address......
    On the form, I have a save button, when i click save button, this will save customer information and I write a function to check if customer name is null or empty.
    I use hot key Ctrl + S for Save button
    protected override bool ProcessDialogKey(Keys keyData)
            {
                switch (keyData)
                {               
                    case Keys.Control | Keys.S:
                        btnSave_Click(btnSave, EventArgs.Empty);
                        break;
                }
                return base.ProcessDialogKey(keyData);
            }
    When I press hot key Ctrl + S, if Customer Name is null or empty, i will show the messagebox: "Customer Name is not null or empty" and I set textbox customer name is focus. But after i set focus to textbox, "S" is added into textbox customer name.
    I don't know why, can somebody help me...
  2. Trinh
    Trinh avatar
    10 posts
    Member since:
    Dec 2010

    Posted 17 May 2011 Link to this post

    Can somebody help me....
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 17 May 2011 Link to this post

    Hello Trinh,

    Thank you for contacting us.

    I was not able to reproduce the described behavior. In my tests on the form I have a button and a textbox. I used the following code:

    void radButton1_Click(object sender, EventArgs e)
         {
             if (String.IsNullOrEmpty(radTextBox1.Text))
             {
                 radTextBox1.Focus();
             }
         }
     
         protected override bool ProcessDialogKey(Keys keyData)
         {
             switch (keyData)
             {
                 case Keys.Control | Keys.S:
                     radButton1_Click(radButton1, EventArgs.Empty);
                     break;
             }
             return base.ProcessDialogKey(keyData);
         }

    I suggest using RadShortcut in this case. Please refer the following help section, where you can find more information.

    If you continue to experience this behavior, please let me know how to modify the code or send me a sample application.
     
    Best wishes,
    Stefan
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  5. Trinh
    Trinh avatar
    10 posts
    Member since:
    Dec 2010

    Posted 17 May 2011 Link to this post

    Hi, thank, it worked, that's great.
    But radTextBox1.Focus() doesn't work...
  6. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 19 May 2011 Link to this post

    Hello Trinh,

    Thank you for writing.

    In my tests, the focus event works correctly. Please find attached a sample project where you can observe my implementation. I suggest that you try to focus the TextBoxElement or the TextBoxItem:

    radTextBox1.TextBoxElement.Focus();
    //or
    radTextBox1.TextBoxElement.TextBoxItem.Focus();

    I hope this helps. Let me know if you need anything else.

    Greetings,
    Stefan
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  7. Trinh
    Trinh avatar
    10 posts
    Member since:
    Dec 2010

    Posted 19 May 2011 Link to this post

    Hi. I will send you my application...
    When i press hot key Ctrl + S, txtCusID.Focus() doesn't work..

    http://www.mediafire.com/?8b5a73go5fmdf6b
  8. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 25 May 2011 Link to this post

    Hi Trinh,

    Thank you for sending me your application. I modified it on a way to give you the desired behavior. Should you have any further questions, do not hesitate to contact me.

    Regards,
    Stefan
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  9. Trinh
    Trinh avatar
    10 posts
    Member since:
    Dec 2010

    Posted 29 May 2011 Link to this post

    Hi, it seem work, but it have a problem.
    When i call Require(), it shows a messagebox if Customer ID null or empty. There are two cases:
    - I use mouse click button "OK" on messagebox, after that it will focus on txtCustomerID textbox.
    - I press "Enter" and after that it won't focus on txtCustomerID textbox.
    I want after I press "Enter" it will focus on txtCustomerID textbox.
    How can I do that. Please help me...
  10. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 31 May 2011 Link to this post

    Hello Trinh,

    Thank you for your question.

    You can achieve this functionality by creating a message box with two buttons - Ok and Cancel - and by also setting the default button of the message box to Button2 (which will be the cancel button). If the dialog result returns OK (this will happen if you click OK button), then you should focus the text box, otherwise, if you press enter, since the default button is the Cancel button, the dialog result will return Cancel and the text box will not be focused. Please refer to a sample implementation in the attached project.

    I hope you find this information helpful.
     
    All the best,
    Stefan
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Back to Top
UI for WinForms is Visual Studio 2017 Ready