ComboBox autocomplete strange behaviour - wpf

Bear with me. I have a ComboBox (WPF) in 'autocomplete' mode.
Easy peasy right? Just set IsEditable to true.
<ComboBox
IsEditable="True"
Text="{Binding Model.TextEntered}"
ItemsSource="{Binding Model.ListWithOptions}"/>
I've got my ComboBox and it autocomplete's just perfect.
BUT when I enter the following text 'caaaaa' it changes it to 'CAaaaa'. I understand the ComboBox autocomplete's the text and match the casing. But when I want to enter caaaaa (for whatever reason) I don't want 'CAaaaa'.
Any idea to solve this?
As an alternative I would settle for (if all else fails):
When leaving the control, check if entered text doesn't match any of the options set text tolower. (as a behaviour)

Have you tried setting ShouldPreserveUserEnteredPrefix="True"? This will not alter the case that is typed into the Combobox but will still match items in the list. So in your example if you type 'ca13' it will find and select 'CA132S', but it will be displayed in the combobox as 'ca132s' (in the case that it was typed in).
A compromise in the way that the item is displayed perhaps, but it will select the correct item and allow you to type characters in either case without alteration.

Try setting IsTextSearchCaseSensitive proprty to true for the ComboBox. Not sure if this property is available in older versions of .NET

Couldn't you use an if statement to check if it matches anything in the list and if it doesn't, don't change it? Like check after each letter entered and if it then doesn't match change it back to the case that was originally entered?
Or is there a reason you want people to be able to type in something that isn't in the list? If not, couldn't you use IsTextSearchEnabled rather than IsEditable?

Related

Restrict the user to type more than maxLength extjs Combobox

I have a combobox with a tpl I wanted to restrict the user not to type more than 8 chars. How can I achieve it as combobox doesn't have enforceMaxLength and maxLength only give a tool tip but allows the user to type the characters more than the maxLength.
https://fiddle.sencha.com/#view/editor&fiddle/1vam
Ext.form.field.ComboBox derives from Ext.form.field.Text, so for all config options available on the textfield, you can check whether combobox really had to override them in a breaking manner, or whether they are still working. Most of them, if not all, should still be available, even if not part of the combobox documentation.
As user chrisuae already pointed out in a comment, enforceMaxLength is still working in combobox. This is because combobox does not remove any of the two parts required intact for maxLength to be available, Ext.form.field.Base.fieldSubTpl or Ext.form.field.Text.getSubTplData.
You may find in the combobox source code that getSubTplData has been overridden, but the line data = me.callParent([fieldData]); means that the original code is still executed.

Editable combobox with binding, block missing values

There are several similiar questions, but they all seems to be asking for the opposite behavior. I have a data-bound combobox, and I want users to be able to locate values in it by typing, as if it were a textbox. This behavior is easy with IsEditable, but it results in the user being able to select values that are not in the ItemsSource.
When a user does this the Combobox highlights red, but thats it. I want it to actually clear the value out, or select the closest match, whichever is easier. Is this possible without also binding to the text, and putting validation logic in the setter?
No, there is no simple way to solve that problem out of the box.
You'll need to either do as you said, bind to the text, or more correctly (in my opinion at least), make a specialized derived ComboBox/attached behavior where you handle this between PreviewKeyPressed, TextChanged, LostFocus etc.
From personal experience, it can be painful to make custom behaviour like that work perfectly.
I agree that what you'd prefer in a perfect world is the readonly combobox, but with improved "search as you type" where you can actually see what you've typed and edit that on the fly.

How to Filter more than one field using WPF AutoCompleteBox

i am trying to customize the suggestions on the AutoCompleteBox in the WPF Tool kit. Right now i have a last name field which when the user enters characters a query runs that retrieves the top 10 records based on that last name. i would also like to filter by first name, i tried splitting out the comma and searching by the last name and the characters entered in the first name.
however, as soon as a space or comma is entered into the autocompletebox, the suggest functionality stops working, which I believe is because the ValueMemberPath property is set to be last name. Is there a work around for this, or a way to modify the ValueMemberPath to handle multiple values? Thanks!
If you wont get any satisfied answer there's a nice control that I'm using from codeproject that supports searching by keywords with easy API.
WPFAutoCompleteTextbox
There's another simple way to get Autocompletebox accept more than one Property for filtering: just use ValueMemberBinding like this:
ValueMemberBinding="{Binding Converter={StaticResource myConverter}}"
and define "myConverter" so that it concatenates your filter properties (properly separated) into a single string; now your AutocompleteBox will use the whole string as it was a single property.

Set textbox to "nothing" in WPF but MV value not updated

I have a user interface where a user can enter a value and that value is updated in the ViewModel (and eventually written back to a database).
This works fine if the a value is actually entered. But if you want to clear that value (i.e. set it to nothing) it doesn't seem to work.
So for example if it was 'dog' but I clear that text and "save" the change is not recognized.
I call "PropertyChanged" which is fired if a value is entered. But if the text is cleared, and I hit enter or tab out of the textbox, the property is not updated.
Is there some special way to deal with this or am I just missing something?
thanks
It ought to work....
Are you sure your other layers (especially the DB) accept 'empty' values? It could be a conversion-exception or error being silently eaten.
To diagnose, experiment with different properties of different types.
The property will not be updated if the data type is an int.
Setting the property as a string will update the property when cleared.
As indicated by Veer in the comments above try using UpdateSourceTrigger as follows to detect when you change the text. Set a break point in your view model and see if you capture the change events when you type in the text box.
<TextBox Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

Having trouble entering time values with MaskedTextbox

I'm using the MaskedTextbox for .NET 3.5 SP1, from the WPF toolkit. I've got a MaskedTextbox on a WPF page, it fills fine from a SQL Server database, but when I tried to edit the value nothing at all happens. I can select anything, but typing over it, or pressing the delete key or anything else I can thing of, does nothing to the value there. I want to use this to allow a user to enter or edit a time value, like this: 9:30 AM would appear as "09:30 AM". Here's the XAML that I've specified:
<cusControls:MaskedTextBox x:Name="mtbTime"
Mask="90:00 >LL" Margin="5,0,0,0"
Text="{Binding ElementName=ThisDateTime,Path=TimePart,Converter={StaticResource NullableTimeToUnderscoreConverter}}" />
(This is a part of a user control I'm making called "ThisDateTime".) What am I doing wrong and how do I fix it?
I haven't seen the source for the text box, but ran into something similar myself.
Could it be a problem with your partially-entered text either not matching the mask, or not matching the converter?
Is the UpdateSourceTrigger on the Binding somehow set to UpdateProperty, or is something similar happening in the code-behind?

Resources