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

Losing focus clears Text when IsFilteringEnabled="True"

9 Answers 143 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 24 Feb 2015, 03:17 PM
Hello,

I want to use the Combobox with IsFilteringEnabled="True" to allow users to select items from a combobox.
However users should also be able to enter new things, that are not (yet) available in the list. Kind of like a recently used list.

When I enable filtering the combobox always clears itself when the focus is lost, thus my users can never enter anything new.
Is there a way to turn this off?
Or is there any other way I can do this?

Thanks!

Regards,
Peter

9 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 26 Feb 2015, 07:51 AM
Hi Peter,

By design when you type a text in an editable RadComboBox and no item matches this text as soon as the control loses focus it is set to null - that behavior is observed when IsFilteringEnabled is set either to True or False.  Could you please provide us some more detailed information about your scenario and the desired functionality -  thus, we could be able to provide you with a prompt approach how to achieve it? 

We're looking forward to hearing from you.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Peter
Top achievements
Rank 1
answered on 26 Feb 2015, 08:39 AM
Hi Nasko,

I know that the RadComboBox does this by design. Thats is why I'm asking how to achieve this.

So here is what I'm trying to do:

I want to be able to give the user a list of his recent queries, think database queries, and the combobox should allow to search in these recent queries, that is the reason for IsFilteringEnabled set to True.

But the user has to be able to enter new queries that do not yet exist in the recent queries.
And that is not possible when IsFilteringEnabled set to True because it clears the text when the focus is lost and the entered text is not in the recent queries list.

I can't attach a project here so here is some snippets of code.

The Xaml looks like this:
<StackPanel>
        <telerik:RadComboBox Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     ItemsSource="{Binding RecentQueries}"
                     IsEditable="True"
                     IsFilteringEnabled="True"
                     TextSearchMode="Contains"
                     OpenDropDownOnFocus="True"/>
         
        <Button Click="ExecuteQuery">
            Execute Query
        </Button>
    </StackPanel>

And the code-behind
public partial class MainWindow : Window, INotifyPropertyChanged
    {
        private string _queryText;
        private readonly ObservableCollection<string> _recentQueries = new ObservableCollection<string>(new []
        {
            "Some old query",
            "Some older query",
            "Some very old query",
        });
 
        public MainWindow()
        {
            InitializeComponent();
 
            DataContext = this;
        }
 
        public string QueryText
        {
            get { return _queryText; }
            set
            {
                if(_queryText == value)
                    return;
                _queryText = value;
 
                OnPropertyChanged();
            }
        }
 
        public ObservableCollection<string> RecentQueries
        {
            get { return _recentQueries; }
        }
 
        private void ExecuteQuery(object sender, RoutedEventArgs e)
        {
            if(String.IsNullOrEmpty(QueryText))
                return;
 
            //Execute the query here.
 
            //Add the query to the recentqueries list to make it available in the future
            if (!RecentQueries.Contains(QueryText))
            {
                RecentQueries.Insert(0, QueryText);
            }
            else
            {
                RecentQueries.Move(RecentQueries.IndexOf(QueryText), 0);
            }
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }


.
























0
Accepted
Nasko
Telerik team
answered on 26 Feb 2015, 02:23 PM
Hello Peter,

One possible approach that we could suggest you in order to achieve the desired functionality is to preserve the Text into a temporary variable and to handle the LostFocus event of RadComboBox. So, when the control loses its focus the event will fire and you could add the preserved variable into he collection of items. Please, check the attached sample project that demonstrates the described above approach.

Hopes this helps.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Peter
Top achievements
Rank 1
answered on 27 Feb 2015, 07:54 AM
I did not notice that the Text property was being set to null.


I was able to solve my problem by disallowing setting of null to my QueryText property.

public string QueryText
{
    get { return _queryText; }
    set
    {
        if(_queryText == value || value == null)
            return;
        _queryText = value;
 
        OnPropertyChanged();
    }
}

Additionally I also had to set CanAutocompleteSelectItems to False to avoid the Combobox automatically selectiong the item that was matching best to the QueryText.

The xaml looks like this:
<telerik:RadComboBox x:Name="RadComboBox" Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     ItemsSource="{Binding RecentQueries}"
                     IsEditable="True"
                     IsFilteringEnabled="True"
                     TextSearchMode="Contains"
                     CanAutocompleteSelectItems="False"
                     OpenDropDownOnFocus="True"/>
0
Nasko
Telerik team
answered on 27 Feb 2015, 11:08 AM
Hello Peter,

We are glad that you've managed to achieve the desired. Please do not hesitate to contact us if you have any additional questions or concerns.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Naresh
Top achievements
Rank 1
answered on 06 Sep 2018, 11:58 AM

Radcombobox clears the text when loaded for the searched filter.

I have entered a text to filter the combo box items, once got filtered the filtered text is cleared.

Also in the first search lets say we select an item(Item1) and for the second search too we selected another item(Item2).

After second search, the first selected item(Item1) gets cleared.

Please help me on this

0
Stefan
Telerik team
answered on 11 Sep 2018, 10:12 AM
Hi Naresh,

In order to enable selection of multiple items, you can set the AllowMultipleSelection property of the control to true. More information can be found in the Multiple Selection help article. As to the filtering text being cleared, can you please elaborate on how exactly is this behavior reproduced?

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Naresh
Top achievements
Rank 1
answered on 11 Sep 2018, 12:27 PM

Hi Stefan,

Thanks for your reply.
we are facing many issues while using Telerik Multi Select drop down.
I request you to please help on each and every issue explained below in detail.

Our scenario is loading multiple values(20k) into multi select drop down.
Below are the issue we are facing in this action:

Issue #1.
Load times is approximately 45sec to bind the control, but after binding and while expanding the item list(by clicking on arrow) took 2mins to expand.
We have tried partial loading by keeping ItemsPerRequest as 500.
Is there any other way to reduce the delay by loading the entire 20k items?

Issue2#:  
During search, when we type a letter, it goes off in seconds.
For example, lets say we entered 's' to filter the results, but the entered letter(s) gets clear without filtering the results.

Issue3#:
In search box the selected items remains same even we clear the selection.
For example, When Item#’s are selected and clicked on the cancel button(x), the item#’s selected are removed in the textbox whereas those are still selected 
in the list displayed(have to manually de-select those)

Thanks in advance

0
Stefan
Telerik team
answered on 13 Sep 2018, 10:23 AM
Hi Naresh,

I will try to address your questions in the same order.

1. RadComboBox can be configured to support UI Virtualization. The downside of this is that filtering is not supported when the control is virtualized. Please, take a look at the RadComboBox Virtualization topic for more information.

2 & 3. I cannot reproduce both of the reported issues. Attached to my reply you can find a sample application which I used for testing. It is the SelectedItems Binding SDK Example. Can you please check it out? Am I missing something?

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Peter
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Peter
Top achievements
Rank 1
Naresh
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or