Combobox showing dropdown on load

2 posts, 0 answers
  1. Keith
    Keith avatar
    5 posts
    Member since:
    Dec 2011

    Posted 02 Apr 2012 Link to this post

    I have a radcombobox that is being bound to an object. It is an autocomplete textbox, so the items are sent as the user types.

    When i clear the selection, or load the page (change binding) the dropdown shows and is open and you have to click inside of it for the dropdown to close.


    <telerik:RadComboBox Height="23" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="6,23,0,0"
                                               DisplayMemberPath="LocationName" telerik:TextSearch.TextPath="Address1" IsEditable="True"  
                                               autocomplete:AutocompleteBehavior.MinimumTextLength="3" Text="{Binding Path=Trip.LocationFrom.Address1, Mode=TwoWay}"
                                               EmptyText="Address 1" Width="313" SelectedItem="{Binding Path=Trip.LocationFrom, Mode=TwoWay}">
                              <autocomplete:AutocompleteBehavior.AutocompleteProvider>
                                  <autocompleteprovider:LocationAutocompleteProvider TextPath="LocationName" />
                              </autocomplete:AutocompleteBehavior.AutocompleteProvider>
                          </telerik:RadComboBox>



    Attached is an image of the behavior as well.

  2. Keith
    Keith avatar
    5 posts
    Member since:
    Dec 2011

    Posted 02 Apr 2012 Link to this post

    I found the issue and the problem is in the  AutocompleteViewModel - in example project 343745_AutocompleteBox.zip.

    line 132 -> protected virtual void OnTextChanged(string newText, string oldText)

    The OnTextChanged method shows the DDL if the text has changed (from "" to null, vice versa, or on initial set). Also selectedItemText was returning null, so I switched it to comparing new to old.
    Changed
    protected virtual void OnTextChanged(string newText, string oldText)
    {
        var selectedItemText = BindingExpressionHelper.GetValue(this.SelectedItem, this.TextPath) as string;
        if (this.Text != selectedItemText)
        {
            this.IsDropDownOpen = true;
        }


    To
    protected virtual void OnTextChanged(string newText, string oldText)
    {        
        if (newText == null)
            newText = "";
        if (oldText == null)
            oldText = "";
        if (newText != oldText && String.IsNullOrEmpty(newText) == false)
            this.IsDropDownOpen = true;
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top