After typing text into a combobox during run time, how do I add it to the combobox's items property? This is in C# 2010.
The simple solution should be something like
Combobox.Items.Add(Combobox.Text);
A more elaborate solution would be perhaps to bind your Combobox.Items to some ObservableCollection in your ViewModel, and on some event (user presses Enter, etc.) the collection is updated by adding the new text (if it's still not there). This solution assumes WPF and MVVM-like approach.
Related
I want to have a Input field where I can input a string. That string could be a new item for that field or I choose to select an existing item. So I do not want Auto-Completion, but Auto-Suggestion which allows me to add entries to the ItemsSource by typing them in.
Basically it is like a normal WPF Combobox with
IsEditable="True"
But how can I get the ComboBox to reduce the list of suggestions to the string I input?
I don't want the ComboBox to present all Items of ItemsSource for selection, but only the ones that contain the string I input.
Can I do it due just setting some ComboBox properties?
For this propose you can use open source solutions like WPF AutoComplete TextBox control or other Autocomplete solutions
For this, I use the DevExpress library. If the ComboBoxEdit is configured correctly, it will auto display a drop down list which is continuously filtered by what the user types. Make sure you set the Mode to Contains, so it matches on any part of what the user types. Users love it as they can quickly narrow down the list of items to select from.
For the record, I am not affiliated with DevExpress. I'm sure Telerik has an equally good control as well.
I have a strange issue with a combobox. The control is bound to a collection that contains a duplicate item, albeit with different case.
They are populated in the list, via databinding, as such:
Babu
BABU
Within the application that I am creating, case is important and both items need to be displayed.
I have the selected item as BABU, yet when I open the combobox, the selectted item immediately changes to Babu without any further intervention from me. I am not handling the DropDownOpening event anywhere so there is no logic there that is causing this.
My suspicions are that it's to do with the databinding not liking what it see's as duplicate entries but I cannot be sure about this.
Has anybody experienced this before?
Open up the Designer code for that form and confirm that BABU and Babu are included in your autocomplete list for that combobox. This happened to me once where I fixed it on the form designer but it never synced up with the form designers code and it ended up containing old unwanted selections.
Also check out your autocomplete modes: http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.autocompletemode.aspx
how can i bind SelectedItems of a ListView?
My ListView has multipleSelection attribute and I'm using CollectionView for its contents..
I've heard about Attached property and I tried implementing this with the one I found here:
Sync SelectedItems in a muliselect listbox with a collection in ViewModel
I can multiple select the items by clicking rows but I can't use the Shift keyboard for multi-selecting many rows instantly... Also, when I filter my collection and refresh it, my selection are all deselected after the refresh..
How can I make it so that whenever my CollectionView refreshes, the previously selecteditems are still selected after the refresh...?
Can someone also help me how to manipulate logically the selected items through my viewmodel?
May be you should add the IsSelected property to the ListViewItem's view model.
You will have to use your own code to keep the selected items after a refresh. Maybe make a copy of your collection before the refresh and afterwards a simple for to check all the checked items in your current collection.
Change your selectection mode to extended for your listbox for the shift key to work.
As for manipulating logically the selected items, you will have to give a lot more info on what exactly you want done.
How to this for combobox?I have long stackpanel which first it has only combobox.And when i select anything from combobox it will be added as button or other thing like on the picture.And it can be closed
[EDIT] I need anything on WPF
This should do the job nicely in WPF; http://www.codeproject.com/KB/WPF/MultiComboBox.aspx
The combo box that ships with WPF does not support selecting multiple
items...
This article describes a WPF combo box that supports both. It also
describes a list box, which the combo box inherits from, that supports
binding to the SelectedItems
Alternatively: WPF: ComboBox with CheckBoxes as items (it will even update on the fly!)
Recently I’ve come across something weird… I needed a ComboBox that will allow the user to select multiple items.
The the solution coming to mind is using CheckBoxes. I have found several examples, but neither one displayed the selected items with pretty commas like this;
i m not sure what you are asking for but you can use this.
jquery tokenizing
what about this?
jQuery Chosen Plugin
http://davidwalsh.name/dw-content/jquery-chosen.php
I'm having issues using a GridView as a ListView's View, what I want to do is fire an event when a user makes a selection from a combobox within the Gridview and pass the selected item within the event.
My first issue is that when the user clicks the combobox within a row, the row isnt selected (meaning the selecteditem stays null unless they click elsewhere first). Is there a clean way to do this without trying to catch mouse clicks or anything?
Secondly theres no selectionchangecommited event on a WPF combobox, is there a cleaner way to check if a user has manually selected an option other than checking if the combobox is enabled?
Thanks
I am seeing a similar behavior. My hypothesis is that one or more layers of the DataTemplate of each item in the list is swallowing the RoutedEvent that should have resulted in a new selection. Is it possible to, in a generic way, tell the items in the DataTemplate that they should never stop the event from bubbeling or tunneling further, without having to override every focus-triggering event handler in code behind?
I 'solved' my issue by using the WPF Toolkit grid (http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29117) and a series of selected items, which is probably a cleaner solution anyway.
Doesn't explain the behavior of the GridView, which is to me unusual
Original link has died, believe this to be the one https://github.com/xceedsoftware/wpftoolkit/wiki/DataGrid