I'm working with an Autocomplete box from the Silverlight Tookit (December release). As the user types, I use a webservice to return an ItemsSource containing a lookup of only the word that the user is currently typing into the AutoCompleteBox (as oppossed to the entire phrase, which is the default behavior). What I'd now like to do is if the user selects an option from the dropdown, I'd like to APPEND that option to the AutoComplteBox, NOT replace it as is happening now.
For example, if the final item should read as "John Smith". Currently, as the user types J-O-H-N, a list containing John will appear and they can select John as needed. As they move on to typing S-M-I-T-H, I've handled the Populating Event to pass only the final word in the .Text property to the Web Service and they will get a list that includes smith. So far, so good. However, when "Smith"is selected from the DropDown, the Contents "John" are REPLACED by the contents "Smith", leaving you with simply "Smith", not "John Smith" as we'd like.
I've attempted to deal with this by writing custom handlers for the DropDownClosing and/or SelectionChanged events. Neither of these appears to be the correct event to handle.
Can someone direct me where I might go to manage this behaviour?
Thanks
Seeing as you're already attaching to the on populating event and presumably kicking off requst to the server for the data, why not just append the 'John ' to all the items in the itemssource before you give it back? Then when you match it'll already be there.
Related
While trying to alter the contents of a combobox on runtime, I stumbled upon a confusing feature.
(Please excuse the many images. I felt that they were severely needed to understand what's going on)
Above you can see my WPF form, my xaml and the codebehind for the Button_Click_1 event.
Incase you were wondering what strings were exactly being saved into this "txt" variable, it was "jon", "ted", "tod" and "adam". As you might expect "jon" would have the index of 0, "ted" of 1, "tod" of 2 and "jon" of 3.
What I want to do is change the "List" assigned to the "ItemsSource" directly without having to reassign a new "List".
What I noticed while testing was that this is definitely possible.
Below you will see the results of me clicking on the button once.
What essentially is happening is that the content of the "test.txt" file is getting saved into the the "txt" variable as a "List".
This variable is then assigned to the "ItemsSource" property of the combobox.
I then proceed to alter the "ItemsSource" directly by removing the item with the index of 1 ("ted").
Lastly, I set the "SelectedIndex" to the item with the new index of 1 ("tod").
When running the program and clicking the combobox to see what items are contained inside the dropdown, I am presented with exactly those three items contained inside of the altered "ItemsSource". ("jon", "tod" and "adam")
Now it starts to get a little more confusing when I decide to click on the button again.
As you can see, after clicking the button a second time, all four items of the "List" get displayed instead of the previous three.
My current theory of how the dropdown of a combobox works is that the content of the "ItemsSource" property gets saved into a sort of cashe which gets used by wpf internally to display the items of the dropdown. This saving of the content seems to also only happen on the first click of the choicebox (textbox). It is then no longer possible to change this cashe by altering the "ItemsSource" directly. Through further testing I also discovered that the only way to change/update this cashe is by assigning a whole new "List" to the "ItemsSource".
Is my theory in some way, shape, or form correct?
I'm using C# TextBox with AutoComplete via a Custom Source of a collection of names, e.g. John Smith, Mary Jane, etc .. The problem is that if I type in 'John', I do see 'John Smith' in the dropdown. But if I start typing 'Smith', I no longer see 'John Smith' in the dropdown. I'd like to change this, and I think I would have to extend the TextBox class and provide my own function for matching data. I just don't know which TextBox function would need to be overwritten.
Secondly, another related issue I'd like to solve this is: The dropdown text is always left aligned. How can I make it center aligned ?
There is no directly way to do it because AutoCompleteCustomSource only allows prefix matching based on your input string.
From TextBox.AutoCompleteCustomSource Property
Use the AutoCompleteCustomSource, AutoCompleteMode, and
AutoCompleteSource properties to create a TextBox that automatically
completes input strings by comparing the prefix being entered to the
prefixes of all strings in a maintained source.
Best option seems to override your OnTextChanged event of your TextBox. The question below has a good example about it;
C# AutoComplete
I have a large collection of items with several parameters, so i'd like to give a user a possibility to have different filters: like order by time, by alphabet, or by categories.
How should i implement filter selection in Metro style? Should it be a menu items like this, but with "filter by alphabet" instead of "menuitem 1" ?
Edit:
Some more details: so, assume we have Movie items with 4 fields: name, year of release, genre and main actor's name. I'd like to allow user to set filtering by 1 of those 4 fields. Actually, it is not filtering or sorting, its more like categorizing.
Ok, i found this thing, looking quite nice.
Edit: though, be careful, it is not working the same as on the picture. At least, current version is not fading the screen, so other controls still would react on user input and Back button.
No way - the AppBar menu is not the way to go. For filtered content, you would normally use LongListSelector (both on WP7 and WP8). The filtering can be set by you when you group (or re-group) the items bound to the control - for the filter setter you could use any control (e.g. a auto-complete text input control or a ListPicker).
I have a WPF combobox. It took me ages to figure out how to make it text editable so that some kind of resonable event fires when both the user enters text and when the user picks an option in the list.
I used this method here (very bottom of the page)
http://social.msdn.microsoft.com/Forums/en/wpf/thread/13c6dfad-4062-41b9-85d8-0d5f23dd349b
But now I have an issue - if I have an option in the comboBox with the text "Apple" for example and i wish to type "Apricot" into the field, as soon as I type the letter A it picks Apple from the list. It leaves the caret after the A so I can continue to write Apricot. However due to the way things listen to the comboBox its vital I can prevent this behaviour but have no idea how.
Any help appreciated as always.
ComboBox.IsTextSearchEnabled = false;
Couldn't find that anywhere. Phew
The above solution works in code, below is how I would do it in XAML.
<ComboBox x:Name="cbCountry" IsTextSearchEnabled="False"
LostFocus="cbCountryLostFocus" KeyUp="cboCountryKeyUp">
Windows explorer in XP will allow you to make a file selection based on typing a few characters. I would like to know if there is any simplistic .net feature I can use to mimic this behaviour in a combobox? I think I've seen this happen in comboboxes before, and would like to know if there is a property I can use?
I know I could develop code around the "Key" events, but can't justify spending the time on it.
For example: In a folder which contains "Apple.doc, banana.doc, cherry.doc, cranberry.doc" then typing "b" will select "banana.doc", typing "c" will select "cherry.doc" but typing "cr" will select "cranberry.doc"
Thanks in advance
G
Have a look at ComboBox.AutoCompleteMode.
Thanks to Daniel for the above answer.
I would also like to point others with a similar queries to AutoCompleteMode which explains the details of each AutoCompleteMode value.
In summary:
None - Disables the automatic completion feature for the ComboBox and TextBox controls.
Suggest - Displays the auxiliary drop-down list associated with the edit control. This drop-down is populated with one or more suggested completion strings.
Append - Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters.
SuggestAppend - Applies both Suggest and Append options.