WPF AutoCompleteBox with ability to add new values to list.
        Posted  
        
            by WillH
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by WillH
        
        
        
        Published on 2010-04-27T10:30:07Z
        Indexed on 
            2010/04/27
            10:33 UTC
        
        
        Read the original article
        Hit count: 836
        
Hi,
I would like to use autocompletebox with a list of values, but also add new values to the list if a user enters one that isn't present.
I currently have a string property in my view model called 'Comment'. Currently this is bound to a textbox in the view - user types a comment and the view model is updated. Simple.
To save time, my customer would like it to autocomplete from previous values, so the way I thought to do this is something like:
ViewModel
public string Comment;
public ObservableCollection<string> CommentsList { ... }
(populate the CommentsList when the viewmodel is created)
View
<AutoCompleteComboBox ItemsSource="{Binding CommentsList}" SelectedItem="{Binding Comment, Mode=TwoWay/>
So when the user selects a value, it saves the value in the Comment property. This works fine if the user selects an item in the list, but if the user types in a new value, the comment property is not updated (it is null because the selected item was not in the list).
Is this possible with autocompletebox?
Thanks in advance, Will
© Stack Overflow or respective owner