Vaadin ComboBox: clear input text on click - combobox

I want a filterable combobox. When I click on the input text, the cursor appears so I can insert some characters into the text.
As typing into the input box is supposed to filter the items in the combobox, the previous text is no longer needed. I want either to:
clear the input text
select all the text (so when I start typing, the
text is cleared) - according to http://dev.vaadin.com/ticket/7116 this is not possible

I have test this on vaadin textfields, it should work for combos too.
You can clear the text on the input capturing the focus event, as in the comments, but instead of using null, use the empty string "", the change will not be seen until you call requestRepaint on the component.
input.addListener(new FieldEvents.FocusListener() {
#Override
public void focus(FocusEvent event) {
input.setValue("");
input.requestRepaint();
}
});
However for this to work you has to lose the focus and gain it again, playing with the valueChange event (override, etc) could be better.

Related

How to 'preselect' text in a TextField so that typing something new immediately replaces the previous text?

It is common practice in many UI situations to preselect the text displayed in a text editing field in such a way that if the user starts typing it immediately replaces the displayed text.
This can be useful for example in search field to show the previously searched text (for reuse or editing) while making it easy to search for a new text string simply by start typing.
I've searched for how to do this in TextField, but not found a way yet - is it possible?
We don't have a concept of pre-select and it isn't common in mobile where selection is awkward by comparison. A more common approach here is to have an X button next to the text field which clears the text field instantly. You can easily do it by just adding a button next to the field.

Losing Focus of Textbox in Silverlight

I have a silver light page in which i am entering some value in a text box (this is not the first Text box in appearance) and clicking on the search button.
After getting the result from the database the focus is losing to and shifting to the first text box which is also a search criteria.
Have you tried anything?
You need to first re focus your Silverlight app, then set the focus to the text box that you want.
try:
this.Focus(); then Dispatcher.BeginInvoke(() => { mytextbox.Focus();});

How do I select all the text in a WPF textbox on click

I have several TextBoxes within a UniformGrid.
I want to select all the within a textbox when it is clicked I'd rather the event came from the uniformgrid. I was able to implement selecting all the text with GotKeyboardFocus for when I use only the keyboard with the code below in the handler. However when I merely click on the box it highlights while my mouse is down and on mouse up the cursor appears rather than the text remaining selected.
foreach(TextBox Box in grid.Children)
{
if (Box.IsKeyboardFocusWithin)
{
Box.SelectAll();
e.Handled = true;
break;
}
}
I also have an PreviewKeyUp handler that watches for a max number of letters then moves to the next box. Also each box is initialized with the max number of letters when the screen loads. Which is why I want to do a select all on the text in the textbox so it can be typed over easily.
I was able to use GotMouseCapture almost perfectly except that it doesn't work if you click near the text only near the edge of the textbox.
Try hooking up to the PreviewMouseUp routed event. That worked for me.

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.

How to prevent Enter press from closing menu

I'm embedding a Colour Picker into a Context Menu using the Windows.Forms.ToolStripControlHost class. The picker displays fine and handles all mouse events properly:
The problem arises when one of the channel sliders is double clicked. This causes the control to add a Windows.Forms.TextBox into the parent control with the same dimensions as the slider so users can enter numeric values. When Enter is pressed while the TextBox has focus, it should assign the value and hide the textbox (which it does), but it also closes the entire menu structure. So, how do I keep the menu alive?
There's an awful lot of code involved but I'll post it if needed.
Somehow, you'll need to eat the Enter key presses before they reach your context menu. Obviously, it's default behavior is to "select" the currently highlighted item when the user presses Enter, just like every other menu control known to man.
You would do that by subclassing the ContextMenuStrip control (if you're not doing so already), and overriding its ProcessCmdKey method. Watch for a keyData value corresponding to Keys.Enter, and when you detect that value, return True to indicate that the character was already processed by the control and prevent it from being passed on for any further processing. Everything else, of course, you'll let the base class process so the behavior of other keys (such as the arrow keys) is unchanged.
For example (I just tested this and it works fine):
public class CrazyContextMenuStrip : ContextMenuStrip
{
protected override bool ProcessCmdKey(ref Message m, Keys keyData)
{
if (keyData == Keys.Enter)
{
// Eat it when the user presses Enter to
// prevent the context menu from closing
return true;
}
// Let the base class handle everything else
return base.ProcessCmdKey(m, keyData);
}
}
And of course, you could add extra checks to the above code so that the Enter key presses are only eaten when your color picker is visible, allowing things to work as expected all the rest of the time,

Resources