Tons of issues with RadComboBox

0 Answers 51 Views
ComboBox
Martin
Top achievements
Rank 2
Iron
Iron
Iron
Martin asked on 04 Jan 2022, 12:37 PM | edited on 04 Jan 2022, 01:08 PM

I'm having some real struggles with RadComboBox ... 


<telerik:RadComboBox x:Name="ModelPicker"
                                 Width="150"
                                 Height="28"
                                 CanAutocompleteSelectItems="False"
                                 DisplayMemberPath="ModelNavn"
                                 IsEditable="True"
                                 IsEnabled="{Binding CanChangeVariant}"
                                 ItemsSource="{Binding Source={StaticResource SortedModels}}"
                                 OpenDropDownOnFocus="True"
                                 SelectAllTextEvent="GotFocus"
                                 SelectedItem="{Binding BrandModel.SelectedCarModel}"
                                 StaysOpenOnEdit="True" />

 

1. ComboBox is AutoSelecting first element when ItemsSource changes

ItemsSource is set to an ObservableCollection<model> and the DataContext implements INotifyPropertyChanged (pretty straight forward MVVM) 

I've tested and found that if I REPLACE the ObservableCollection instead of Clear() + Add() , the UI update is MUCH faster. 

eg:

ItemsSource="{Binding MyModels}"

MyModels = new ObservableCollection<model>(/* List of Models */); 

HOWEVER - this causes the RadComboBox to AutoSelect the first element !!!

(to be fair - this is actually also how Microsoft WPF ComboBox works) ..  :-( 

 

2. CanAutocompleteSelectItems="False" is ignored

On almost every keystroke I do when AutoCompleting / Filtering - the ComboBox selects whatever item is partially matching 

eg : list contains 1000, 114i, 114 and 114d 

if I write "1" then 1000 is selected,

if I write "114d" and delete "d" then 114 gets selected. 

I'm pretty sure that CanAutoCompleteSelectItems=false should prevent this ??

 

 

Martin Ivanov
Telerik team
commented on 07 Jan 2022, 10:29 AM

I couldn't reproduce neither of those issue. Can you check the attached project and let me know if I am missing anything? Also, can you share the exact steps to reproduce the described behaviors?
Martin
Top achievements
Rank 2
Iron
Iron
Iron
commented on 07 Jan 2022, 12:26 PM

hi - thanks for the sample and your time looking into this. 

I used your example and tried replicating my issues. 

what i found is that when the source of the ComboBox is a CollectionViewSource (as my code uses) :

    <CollectionViewSource x:Key="SortedModels" Source="{Binding ElementName=root, Path=ItemList}">
        <CollectionViewSource.SortDescriptions>
            <scm:SortDescription Direction="Descending" PropertyName="ModelNavn" />
        </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>

Then the selected element changes when replacing the ItemsSource. So maybe its an issue within WPF ? 

 

regarding issue #2 - it could be an issue when a debugger is attached , I've added the altered sample. 

I can replicate this by running the sample and simply changing text in the combobox.

Martin
Top achievements
Rank 2
Iron
Iron
Iron
commented on 07 Jan 2022, 12:32 PM

I found that IsSynchronizedWithCurrentItem = false seems to fix issue #1
Martin Ivanov
Telerik team
commented on 07 Jan 2022, 01:25 PM

Yes, this behavior is expected. The IsSynchronizedWithCurrentItem is part of the native Selector class which is inherited by RadComboBox. You will see this behavior also with other selectors like ListBox for example. Basically, the property tells if the SelectedItem of selector (like RadComboBox) should be synchronized with the CollectionView's CurrentItem property. Since, the default CurrentItem is the first one in the CollectionView, the described behavior appears.

So, the resolution to issue one is to set the IsSynchronizedWithCurrentItem property to False.

About issue #2, I still can't replicate this. First, I start the application and start typing. Nothing happens because no items are presented. Then I click on the button to reset the ItemsSource and start typing again (using text contained in the newly loaded items). At this point nothing happens. I've tested this with IsSynchronizedWithCurrentItem set to True and False.

Martin
Top achievements
Rank 2
Iron
Iron
Iron
commented on 07 Jan 2022, 02:51 PM

I've screencaptured issue #2 

https://www.youtube.com/watch?v=jdIvVJDxcY4

 

Martin Ivanov
Telerik team
commented on 12 Jan 2022, 12:01 PM

Thank you for the video.

The CanAutoCompleteSelectItems property is designed to work only when the drop down part of the ComboBox is opened. Otherwise, the selection always happens. You can avoid this by manually opening the drop down whenever the user type. For example:

private void ModelPicker_Loaded(object sender, RoutedEventArgs e)
{
	var textBox = this.ModelPicker.FindChildByType<TextBox>();
	if (textBox != null)
	{                
		textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
		textBox.AddHandler(TextBox.MouseLeftButtonDownEvent, new MouseButtonEventHandler(TextBox_MouseLeftButtonDown), true);
	}
}

private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
	this.ModelPicker.IsDropDownOpen = true;
}

private void TextBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
	this.ModelPicker.IsDropDownOpen = true;
}

No answers yet. Maybe you can help?

Tags
ComboBox
Asked by
Martin
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or