Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combox column in wpf datagrid performance issue

I have a wpf form which contains a datagrid. 1 of the columns in the datagrid is of type combobox. There are 1000's of items in the ItemsSource property of the combo-box. Hence it takes significant amount of time to display the values when the arrow besides the combo-box (rendering issue, I believe) is clicked. How can we make the combo-box display the items faster, virtually with no lag?

like image 737
RohanDsouza Avatar asked Oct 23 '25 04:10

RohanDsouza


1 Answers

Try putting this onto your combobox. Rather than loading all of the items at once, this should make it load them as you view them.

For inside a datagrid, i always use a DataGridTemplateColumn for my combobox columns:

 <DataGridTemplateColumn Header="My Combo Column">
       <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                 <ComboBox Margin="0" ItemsSource="{Binding Path=DataContext.MyCollection, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"
                   SelectedItem="{Binding Path=Item.Property, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
                        <ComboBox.ItemsPanel>
                             <ItemsPanelTemplate>
                                  <VirtualizingStackPanel Width=250 VirtualizingStackPanel.VirtualizationMode="Recycling" CanHorizontallyScroll="True"/>
                             </ItemsPanelTemplate>
                        </ComboBox.ItemsPanel>
                 </ComboBox>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
 </DataGridTemplateColumn>  
like image 137
emybob Avatar answered Oct 24 '25 18:10

emybob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!