How to keep focus in MessageBox - extjs

I am using EditorGridPanel with cellEditor which acts nearly like Excel. We implemented Arrow Keys to move among rows and columns.While validating a row, if it does not match the validation rule we show a MessageBox and hope that focus does not move if it is not valid. But, after the MessageBox shows - focus moves to the next row/column. Another problem is, user have to click in the OK button of the MessageBox to remove that from screen. Can we have the focus on the invalid column editor and also focus on the MessageBox OK button - so that user can press Enter to hide the message and continue entry?
Please check our link. http://www.softworksbd.com/swazilandlmis/yyyy_stockdata.php

Only one element can be focused, so focus should go to the message box. AFAIK enter/escape keys works out of box with message box.
You can pass callback to the messagebox. In this callback you can focus desired cell in the grid. Like this:
Ext.Msg.alert('Title', 'Message.', function(){
this.startEditing(rowIndex, colIndex);
}.createDelegate(grid));
So after message box is closed, the focus will go back to the editor.

Related

Handling/capturing a button click event as a priority in WinForms

This is the mock-up of a child window that I have in a Windows Forms application.
This will be shown when a button is clicked on the parent window.
When the child form opens up, the focus is in Text box1.
The Leave event on the Text box1 fires when the user tabs out of it or clicks on any button.
This triggers a validation:
if(String.IsNullOrEmpty(textBox1.Text)
{
MessageBox.Show("Please enter a value of Id.");
}
else {
... other logic omitted for brevity
}
Now the user can also click on the Cancel button to exit the form without doing any action.
Here, on the first try, the Leave event fires because the focus is in Text box1 when the Form is loaded so when the user clicks on Cancel for the first time the form does not close, instead the message box with validation message is shown.
On the second click, since the focus is no longer on Text box1, the Leave event does not fire and the form closes.
I can put the focus on any other control to handle this but for the sake of user experience I had to put the focus on Textbox1 since it's value decides the further logic of what is shown in Textbox2(Textbox1 can be left empty in which case nothing is shown in Textbox2 but that is not related to this question).
Tried this to see if I can get the Cancel button inside the Leave event of Textbox1:
Button b = sender as Button
b is NULL when Cancel is clicked.
What can I do to make the Cancel click work, without triggering the Leave event initially?
Thanks in advance,
Regards.
If you only want to supress the error message when the cancel button recieves the focus, simply check for the cancelButton.Focused flag in the leave event, then block the message if the cancel button got the focus.
Nevertheless, it is usually considered good practice to avoid modal dialog boxes if they are not required. So depending on your particular situation, you may decide to replace the MessageBox with a ToolTip instead, which will not entirely block the UI thread.

How to set focus on textbox and button simultaneously in WinForm

I want to set focus on a button while caret is present in textbox and user can still enter data to textbox. But when user presses enter key, button press will be simulated.
I am currently using a work around to solve this problem by handling onKeyDown event and checking for enter key. But problem is there is no clue for user to understand this as there is not blue border around the button that indicates focus on button.
Here is a example of what I want to implement (user can enter text in textbox while focus is on :
I have tried to search on google and StackOverflow but could not find any relevant result.
This is a fundamental Windows principle. It's not possible to have 2 controls (windows) focused at the same time.
So the focus should be inside the text box. But you can get the visual indication needed by setting the ok button as AcceptButton of the form (you might also want to set cancel button as CancelButton).
In the form constructor, load event or using designer:
this.AcceptButton = okButton;
There is no need to handle KeyDown event - as soon as the text box is not multiline, pressing Enter while the focus is inside it will generate ok button click. The same applies for the button set as CancelButton when you press ESC.

Buttons keeping their focus class after losing focus

I have some buttons in a bottom toolbar of a gridpanel that control adding, and removing records from the row-editing grid.
The handlers are pretty simple: "new" button creates an instance of the model, appends to the grid and then opens a row-editor on the new row; "edit" button just opens the selected row's row-editor; "remove" destroys the record from the store and refreshes the grid view.
For some reason these buttons don't lose the focus class that gives them a border when they have the focus. Here is a picture:
In the picture both the "New" button and the "Remove" button have the focus class, when I press the "Edit" button it also keeps the focus classes even after doing a complete row-edit operation and closing the row-editor.
I did find that when I mousedown on one of these permanently "focused" buttons and then mouseup away from it and then click something else the focus class goes away.
I know that I could put a blur handler for all button components in my respective controllers but I would have thought that this functionality was built in so I am asking to see if there is something I missed somewhere in the docs.
The classes that it won't let go of are these:
x-focus x-btn-focus x-btn-default-toolbar-small-focus
This is with ExtJS 4.1.0 in FF10 on Windows 7. But I did notice similar behavior in ExtJS 4.02 and 4.07, just haven't needed to handle it until now.
I found out what it was:
At some point in the handler chain for each of these buttons the button gets disabled. When a button is disabled in ExtJS it prevents the blur event from firing.
It was necessary to disable the buttons so the solution to simply add button.blur() in the handler was the correct way to do go about it.

In WPF how to determine how focus received

I have a text box on a form and want to perform different actions when it receives focus depending on how the focus was received.
If the user clicks on the text box I want the standard method where the cursor is placed at the end of the text string inside the box. If the user tabs to the text box I want all of the text contained within the text box to be selected.
Is there an elegant way to accomplish this?
I suppose one thing you could try would be to set some application-level (or parent-level) tunneling events so you can toggle a flag indicating it was mouse clicked or keyboard pressed (PreviewMouseDown and PreviewKeyDown). Depending on what was previously pressed by checking that flag, you could do the appropriate action when the text box gets focus.

WinForms Accept Button Annoyance

I have a base panel class that has (among other things) three buttons. I use subclasses of this base class in two different config dialogues. Both dialogues have an OK button set as the accept button.
In one of the dialogues, if I click one of the buttons in the base class, focus immediately returns to the OK button, so pressing the enter key works as expected.
In the other dialogue, focus remains wth the button in the base class that was clicked if it is enabled, or moves to the next button if the clicked button is no longer enabled.
There is no code that handles the base class button click events in either of the derived classes.
Ideas anyone?
I'm not sure what's going on in your first dialog because it doesn't seem to be operating the way I would expect it to. The second dialog sounds more like the standard behavior.
In Windows Forms, the AcceptButton property only comes into play when pressing Enter doesn't otherwise cause any actions. In both of your examples, clicking on a button should move the focus to that button, and subsequently pressing Enter would cause another click on that button.
In any event, I think it's generally preferable to stick with the Windows user interface guidelines and not automatically change the input focus back to the OK button. If the user clicks on one of the other buttons, the focus should stay there until they move it.
i don't know what language you are using, but the button class should have a focus method that will highlite it for enter pressing. in the click method, or when you open the dialog you can call this method to make the button you want get the form's focus
c#
myButton.Focus();

Resources