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

Large colllections

3 Answers 304 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Przemysław
Top achievements
Rank 1
Przemysław asked on 21 Jul 2015, 08:50 AM

Hi,

I'm trying to create a generic combo box to select one of out business objects. I will try to show ou the scope:

Control (lets call it like this) GenericCombobox<Person>:
- Automatically loads items source from db when loaded (this is done asynchronously)

- the itemsssource is VirtualQueryableCollectionView created upon Telerik's Data Access query similar to db.GetAll<People>();

- Has one consistent template

- Allows to bind to SelectedItem

The intention is to create one consistent Selector for most of our BO - like Person, Customer, Order, Country just by creating inherited controls like CustomerCombobox : GenericCombobox<Customer> and putting in in xaml without having to manage itemssources.

 

I have few problems - combobox is loading all items from VirtualQueryableCollectionView - for our orders collection this is over 150k items. And since we will have for example 5 comboboxes on one view memory usage of application is running very very high.

 

Is there any way, to dynamically load items source - for example only show first 100 results matching search text? I tried to do something similar but I run into issues, because in most cases our currently selected item is not in these 100 first results. And when selected item is not in itemssource - we're losing selection.

 Cheers

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 24 Jul 2015, 06:13 AM
Hello Przemysław,

I am afraid that by design the ComboBox cannot have SelectedItem that is not in its ItemsSource.
So its seems like you have few options like:
  • Don't load all of the items and implement custom logic for keeping the LastSelectedItem, for example with custom Dependency Property and bind to it instead of SelectedItem.
  • Don't load all of the items, but always add the last selected item in the ItemsSource (in this case if you don't want it to be seen in the drop down you may need to apply CustomFilteringBehavior).

Hope this would help.


Regards,
Georgi
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Przemysław
Top achievements
Rank 1
answered on 24 Jul 2015, 08:29 AM
Georgi,

I already have custom property to temporary store selected item - because in most cases binding is done before async loading of items source is completed. So after that I'm setting it again. But this is not a dependency property.
I will try to follow your suggestion and bind to custom dependency property - hope it helps. I'll post here my findings.

About other bullet points,
Yesterday i tryied to achieve something similar to your second proposal. But when I try to switch item sources (selecting for example 'selected item' and 19 others matching search text) - control is automatically selecting first of them. So Text property is changing, and my search is doing nothing...
This is strange, because all objects have IComparable methods based on database Id - so selected item from new itemssorce should be treated as identical (?).
I'll try to do something with value coercion there, maybe that's the issue. 

I don't think loading all items would be viable - since our Open Access objects can be pretty heavy loading a list from a table with over 200k objects would take a lot of memory, even when virtualization of UI. Currently we have a view with 7 comboboxes - opening it takes up to 200MB of RAM. And since application is based on 'web browser' like tabs, it's pretty easy to go past 1GB of RAM. Not even mentioning that loading all those items is taking too much time.
I currently have one global items source for all Comboboxes of one type - it's something like ComboboxItemCache<Order>, but even if this is one collection per Type for whole application - its still hundreds of thousands of Open Access objects... And from my experience they have some overhead on memory - when i run JustTrace the biggest memory takers are DataAccess objects (see attachment)
I don't want to make a copy of database in user's PC memory...

We already tried to use AutocompleteBox, but our users didn't like it. Search was working in strange way, also selected value was changing every time we typed something. And since we have 'Property change log' for our businessobjects - there were a lot of trash items there.
Also because of this change log, it would be nice if that property wouldn't be set twice while binding. It was happening at first, but i prevented it in 'CoerceValue' events.

I think other option is to create a custom control similar to combobox - see attachment. 
But since I had never created a control from scratch, I don't really know how much time it will take to code and then style it to match telerik themes.


If you have any other ideas please share.
Thanks for help.
0
Georgi
Telerik team
answered on 27 Jul 2015, 08:34 AM
Hi Przemysław,

I hope that using dependency property would do the trick.

Also it seems like in order the SelectedItem and the one from the new ItemsSource to be treated as identical implementing IComparable is not enough and you also need to override the Equals, GetHashCode and the == operator as shown in this thread.
So as this logic comes from the Microsoft Selector I have tested it in simple project and the suggestion worked like a charm.

Nevertheless if you decide to create your custom control you can use other controls like DropDownButton and ListBox as parts so you would save some work styling it.


Regards,
Georgi
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Przemysław
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Przemysław
Top achievements
Rank 1
Share this question
or