Bind Combobox with huge data in WPF
I am trying to bind combobox with custom object list. My object list have around 15K record and combobox takes long time to show the data after clicking on combobox.
Below are the code:
<ComboBox Height="23" Name="comboBox1" Width="120" DisplayMemberPath="EmpName" SelectedValue="EmpID" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"/>
code behind:
List<EmployeeBE> allEmployee = new List<EmployeeBE>();
allEmployee = EmployeeBO.GetEmployeeAll();
comboBox1.ItemsSource = all开发者_运维问答Employee;
allEmployee have around 15K record. Can any one Suggest how can I improve my combobox performance?
That's bad UI design: No user will read through 15K records.
You can improve the performance by allowing the user to enter some filter criteria before showing the results, for example, by using an AutoCompleteBox instead of a ComboBox.
You could try a VirtualizingStackPanel
as described here - http://vbcity.com/blogs/xtab/archive/2009/12/15/wpf-using-a-virtualizingstackpanel-to-improve-combobox-performance.aspx
As others have said, you really want to re-imagine your UI, as a ComboBox isn't appropriate for 15k records.
Try using a VirtualizingStackPanel
as ItemsPanel
for the ComboBox
.
<ItemsPanelTemplate x:Key="ComboBoxItemsPanelTemplate">
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
<ComboBox ItemsPanel="{StaticResource ItemsTemplate}"/>
精彩评论