This is a migrated thread and some comments may be shown as answers.

Problem with ProcessKeyDialog

8 Answers 109 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Trinh
Top achievements
Rank 1
Trinh asked on 12 May 2011, 02:53 AM
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...

8 Answers, 1 is accepted

Sort by
0
Trinh
Top achievements
Rank 1
answered on 17 May 2011, 08:28 AM
Can somebody help me....
0
Stefan
Telerik team
answered on 17 May 2011, 09:59 AM
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.
0
Trinh
Top achievements
Rank 1
answered on 17 May 2011, 10:32 AM
Hi, thank, it worked, that's great.
But radTextBox1.Focus() doesn't work...
0
Stefan
Telerik team
answered on 19 May 2011, 04:39 PM
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.
0
Trinh
Top achievements
Rank 1
answered on 20 May 2011, 02:00 AM
Hi. I will send you my application...
When i press hot key Ctrl + S, txtCusID.Focus() doesn't work..

http://www.mediafire.com/?8b5a73go5fmdf6b
0
Stefan
Telerik team
answered on 25 May 2011, 06:54 AM
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.
0
Trinh
Top achievements
Rank 1
answered on 30 May 2011, 03:04 AM
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...
0
Stefan
Telerik team
answered on 31 May 2011, 02:01 PM
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.
Tags
General Discussions
Asked by
Trinh
Top achievements
Rank 1
Answers by
Trinh
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or