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

Filter not work with custom data template

1 Answer 25 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Aeroth
Top achievements
Rank 1
Aeroth asked on 21 Jan 2013, 10:15 AM
Hi Telerik Support,

I wrote a simple ComboBox with my custom data template but the filter functionality does not work properly. E.g., I added 5000 items to my ComboBox (from 1 to 5000) I can find the value of 3333 by scrolling down the ComboBox, but if I filter with 3333 some values are gone.
Did anything go wrong? Thanks!
Below is my code:

public class MyComboBox : RadComboBox
    {
        private MyComboBoxItemCollection _itemList;
 
        public MyComboBox()
        {
            this._itemList = new MyComboBoxItemCollection();
            base.IsEditable = true;
            base.IsFilteringEnabled = true;
            base.StaysOpenOnEdit = true;
            base.TextSearchMode = Telerik.Windows.Controls.TextSearchMode.StartsWith;
            base.IsReadOnly = true;
            DataTemplate selData = (DataTemplate)XamlReader.Load(
              @"<DataTemplate
                        xmlns=""http://schemas.microsoft.com/client/2007"">                   
                        <TextBlock Text=""{Binding Value}""/>                                           
                </DataTemplate>"
              );
 
            DataTemplate itemTmp = (DataTemplate)XamlReader.Load(
                @"<DataTemplate
                        xmlns=""http://schemas.microsoft.com/client/2007"">
                    <StackPanel Orientation=""Horizontal"">
                        <TextBlock Text=""{Binding Value}""/>
                        <TextBlock Text="" ""/>
                        <TextBlock Text=""{Binding Description}"" Foreground=""Blue"" />
                    </StackPanel>
                </DataTemplate>");
 
 
            ItemsPanelTemplate itemsPanelTmp = (ItemsPanelTemplate)XamlReader.Load(
                @"<ItemsPanelTemplate
                        xmlns=""http://schemas.microsoft.com/client/2007"">
                    <VirtualizingStackPanel />
                </ItemsPanelTemplate>");
 
 
            base.SelectionBoxTemplate = selData;
            base.ItemTemplate = itemTmp;
 
            base.ItemsPanel = itemsPanelTmp;
 
            base.SelectedValuePath = "Value";
            Telerik.Windows.Controls.TextSearch.SetTextPath(this, "Value");
        }
 
        public void Add(string showText, object description, object value)
        {
            MyComboBoxItem item = new MyComboBoxItem()
            {
                DataContext = value,
                Value = showText,
                Description = description == null ? string.Empty : description.ToString(),
            };
 
            _itemList.Add(item);
 
            base.ItemsSource = _itemList;
        }
 
        public void Add(object value, object description)
        {
            this.Add(value.ToString(), description, value);
        }
 
 
        public void Add(object value)
        {
            this.Add(value, "");
        }
    }
 
    public class MyComboBoxItem
    {
        public string Value { get; set; }
        public string Description { get; set; }
 
        public object DataContext { get; set; }
 
    }
 
    public class MyComboBoxItemCollection : ObservableCollection<MyComboBoxItem>
    {
        public MyComboBoxItemCollection()
            : base()
        {
        }
    }


Regards,
Aeroth Lin

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 24 Jan 2013, 08:23 AM
Hi Aeroth,

I noticed in your code that you're using VirtualizingStackPanel - note that virtualization and filtering features in RadComboBox cannot be used together. The reason for this is that RadComboBox is an ItemsControl. I would suggest to check our RadAutoCompleteBox control which supports such scenarios.

All the best,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ComboBox
Asked by
Aeroth
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or