Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using C# WPF and currently, I am loading some data from the database in Datagrid.

I loading more than 24,000 rows from a table in the database into DataGridComboBoxColumn, the problem is that when I open the Combobox it is very slow so it takes about 30 seconds to display the records

I don't want use DataGridTemplateColumn because in the combobox element doen't firing the CellEndEdit event

so I'm using DataGridComboBoxColumn

<DataGridComboBoxColumn Width="160" Header="DataGridComboBoxColumn"
                                        SelectedValueBinding="{Binding CommodityID}"
                                        DisplayMemberPath="CommodityName"
                                        SelectedValuePath="CommodityCode">
                    <DataGridComboBoxColumn.ElementStyle>
                        <Style TargetType="{x:Type ComboBox}">
                            <Setter Property="ItemsSource" Value="{Binding Path=TheCommodityCombo_DATA, RelativeSource={RelativeSource AncestorType=Window}}" />
                        </Style>
                    </DataGridComboBoxColumn.ElementStyle>

                    <DataGridComboBoxColumn.EditingElementStyle>
                        <Style TargetType="{x:Type ComboBox}">
                            <Setter Property="ItemsSource" Value="{Binding Path=TheCommodityCombo_DATA, RelativeSource={RelativeSource AncestorType=Window}}" />
                            <Setter Property="SelectedIndex" Value="0"/>
                            <Setter Property="IsEditable" Value="True"/>

                            <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
                            <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
                            <Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/>
                        </Style>
                    </DataGridComboBoxColumn.EditingElementStyle>
                </DataGridComboBoxColumn>


My issue is : the settings that I made exactly like the ComboBox in DataGridTemplateColumn do not work for the DataGridComboBoxColumn! and DataGridComboBoxColumn on opening combobox is so much slow


Full explanation cross post : https://stackoverflow.com/questions/73590406/why-is-the-comboboxcolumn-very-slow-on-drop-down-open-in-datagrid-wpf
How do I fix this ↑ ?

What I have tried:

<ComboBox.ItemsPanel>
    <ItemsPanelTemplate>
        <VirtualizingStackPanel VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling"/>
    </ItemsPanelTemplate>
</ComboBox.ItemsPanel>
Posted
Comments
Richard MacCutchan 3-Sep-22 6:24am    
24,000 rows in a ComboBox!
mojtabahakimian 3-Sep-22 6:26am    
24000 customers name Why <setter property="VirtualizingStackPanel.IsVirtualizing" value="True"> it's not working for DataGridComboBoxColumn ?
Richard MacCutchan 3-Sep-22 6:28am    
But it still needs to access all the data to decide how to display it. And what user is going to scroll through 24,000 items?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900