This is a migrated thread and some comments may be shown as answers.

Combobox showing dropdown on load

1 Answer 99 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 02 Apr 2012, 04:32 PM
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.

1 Answer, 1 is accepted

Sort by
0
Keith
Top achievements
Rank 1
answered on 02 Apr 2012, 06:29 PM
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;
Tags
ComboBox
Asked by
Keith
Top achievements
Rank 1
Answers by
Keith
Top achievements
Rank 1
Share this question
or