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:
Regards,
Aeroth Lin
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