sanjay jadam
sanjay jadam

Reputation: 221

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 = allEmployee;

allEmployee have around 15K record. Can any one Suggest how can I improve my combobox performance?

Upvotes: 3

Views: 4458

Answers (3)

Yiğit Yener
Yiğit Yener

Reputation: 5986

Try using a VirtualizingStackPanel as ItemsPanel for the ComboBox.

<ItemsPanelTemplate x:Key="ComboBoxItemsPanelTemplate"> 
   <VirtualizingStackPanel/> 
</ItemsPanelTemplate>

<ComboBox ItemsPanel="{StaticResource ItemsTemplate}"/>

Upvotes: 0

devdigital
devdigital

Reputation: 34349

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.

Upvotes: 4

Heinzi
Heinzi

Reputation: 172290

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.

Upvotes: 5

Related Questions