In a Silverlight web app that I'm working on, there's a DataGrid with a column that displays as a DatePicker. The DatePicker gives the option to change its value by typing in the box, or by clicking on the calendar button and selecting the date. In the case where text is entered, if the cell loses focus then the entered value is lost and the old value is displayed. If text is entered and then the Enter key is pressed, then the value is kept when the cell loses focus.
Also curious is that other editable cells in this grid already keep their information without needing to first hit enter.
Is there a way to have the value kept without having to press the Enter key? There's obviously some sort of built-in event happening when the Enter key is pressed in order for this to work. Maybe I can use the LostFocus event to fire whatever the Enter key is using? What's going on here?
You may want to try using the keydown event and trap all keystroke then flush the data to where this control was bound.
Related
I am writing a WPF application where we are supposed to shift focus from one button to another by pressing the TAB key.
All is fine, but for a specific page, there is a textbox which is always focused so that the user can type in it immediately. But now, when I press TAB, the focus is shifted to the button (which is as per requirement) but as the focus is lost from the textbox, I cannot type anymore.
I want to have a behavior where I can keep the Keyboard focus on textbox but should be able to control the buttons using TAB key as well. In a way, I need to have focus on textbox and the buttons at the same time. Is this possible?
Tried the FocusManager.IsFocusScope = "true", but this did not help.
I have a problem with the RegularExpressionValidator. This seems to be issues with the validator itself.
The problem occurs with Firefox because it has an autocomplete dropdown, however it could also have the same issue on other browsers.
Problem 1
If I focus inside a textbox, Firefoxes autocomplete displays. If I highlight a valid entry but press enter rather than say tab, a validation error occurs, even though the value is correct.
If I tab outside the textbox the message resets.
Problem 2
If I repeat the process that caused problem 1, by focusing back into the textbox letting firefox display auto complete and pressing enter again, the same problem occurs however this time the validator is not cleared when focus moves outside the textbox and the error message remains visible.
Any advice?
Your issue is related to the fact that you're pressing the Enter key, which causes a postback. When the page posts, it sends the state of each control at the time you pressed Enter, so the value you chose from the autocomplete dropdown wasn't populated yet. My recommendation would be to disable the Enter key when the textbox has the focus.
You can find an example of that here.
Is there a way in silverlight to detect when a lost focus event is triggered if this
happens because the tab key is pressed or the user presses a mouse button on another control.
This is what i want to achieve:
I have a RadGridView with 1 row. In the last column i have a numeric input, when
an user tabs out of this control, a new row should be added to the sourcecollection in the viewmodel, this automaticly adds a new row to the grid, then the first column on this row should have focus and the dropdownlist in the celledittemplate should be opened.
When i use the lost focus event adding the new row works fine, though this also works when i don't use tab to unfocus the control. Also, the first column on the new row is not selected, it somehow
gives focus to row 0 column 0.
Ok, inspired by the answer Dipak gave I came up with a slightly different solution,
I handled the Gridviews keydown and keyup events, keydown sets a bool to true, keyup to false.
the execution sequence fortunately is keydown, lostfocus, keyup
so in the lost focus event I only need to check wether the bool is true;
strangely enough the keyup event is not always triggered, but since the lostfocus is
I set the bool to false there also.
yes you can trace it, Provided you have implemented mouse up/down event on each focusable element on your screen. You will have flag to check if mouse preview event up/down happen on any element, if not then its TAB key which cause lost focus.
This is work around if some one not suggest proper solution.
I have a feature request that when a ComboBox is 'clicked into' that it clears the text so that the user can start entering in new data to search. Does anyone know of a way to hook into this? The 'click' event is raised on when the text is clicked as well as when the drop down arrow is also clicked (which opens up the drop down with items). I only want it to happen on the first, not the latter.
Right now I'm capturing the click event and filtering on the DroppedDown property like so:
if(!comboBox.DroppedDown)
{
// clear selection
}
This seems to work most of the time, but bugs out frequently as well... so its not 100%.
If anyone knows of a proper way to do this I would appreciate!
Don't handle the click event. For one thing, it won't fire if the user tabs the focus into the control. Use the Enter event which fires when the control receives focus. And rather than clearing text you should just select it all which will give the best of both worlds:
1) The user can start entering new text which will clear any old text or
2) tab past the control and leave the contained text as it was.
If you always remove the previous text you may anger users.
Try the "Enter" event. It happens when a control gains focus on the form.
I have made a custom view in which i have used a search box which is a text box to search specific directory.When we press Enter key on the search box i search the directory and if found then refresh my custom browser to dispaly the new diretories content. but the problem is when i am in modal dialog then i could not detect the Enter key press event in the search box though i could detect the others key press event. When I press the Enter key it just change its focus to the windows Edit control and it does not execute any event like KeyPress/KeyDown etc.
Any suggestions
By default the Enter key is ignored by the TextBox when it is a single line control, as there is no need for it to have any response to an Enter key event. To overcome this you need to create a new class that derives from the TextBox and override the IsInputKey method. Inside here check if it is the Enter key and return True. This means the the key will be sent to the control because the control wants to process it. Then you can KeyDown for the TextBox as expected.