Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys ,
i have A data grid in in A WPF Windows Form , This data grid has a DatagridComboBoxColumn this ComboBox Filled With From 10000 to 20000 Item user can choose any one from them through this Combo Box I Bind This Large number in the Combo Box and when user type in the combo Box ,Auto Drop down is Opened but the problem is As the Large number of Items which was bidden from the data table to the combo box the auto drop down take some time to be opened and that make the search in the combo box is so complex is there any advice to make that easier and satisfy the user more and more

thanks in advanced

My XML Code
HTML
<datagrid name="DG_Order" grid.row="3" margin="5,20,5,5" removed="White" canuseraddrows="False">
                  CanUserDeleteRows="True" CanUserReorderColumns="False" AutoGenerateColumns="False" PreviewKeyDown="DG_Order_PreviewKeyDown"
                  ItemsSource="{Binding}">
            <datagrid.resources>
                <resourcedictionary>
                    <resourcedictionary.mergeddictionaries>
                        <resourcedictionary source="/PresentationFramework.Royale;component/themes/Royale.NormalColor.xaml" />
                    </resourcedictionary.mergeddictionaries>
                </resourcedictionary>
            </datagrid.resources>
            <datagrid.columns>
                <datagridtextcolumn loc:translate.uid="1656" header="{loc:Translate  رقم المسلسل}" width="Auto" binding="{Binding Index}" isreadonly="True" xmlns:loc="#unknown" />                
                <datagridcomboboxcolumn loc:translate.uid="1658" header="{loc:Translate كود الصنف}" width="*" xmlns:loc="#unknown">
                                        DisplayMemberPath="Code"  SelectedValuePath="Med_ID"       
                      SelectedValueBinding="{Binding Path=Med_ID,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                </datagridcomboboxcolumn>
                <datagridcomboboxcolumn loc:translate.uid="1658" header="{loc:Translate الصنف}" width="3*" x:name="Name" xmlns:x="#unknown" xmlns:loc="#unknown">
                                        DisplayMemberPath="Name_latin"  SelectedValuePath="Med_ID"       
                      SelectedValueBinding="{Binding Path=Med_ID,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                    <datagridcomboboxcolumn.editingelementstyle>
                        <Style TargetType="ComboBox">
                            <setter property="BorderBrush" value="Transparent" />
                            <setter property="IsEditable" value="True" />
                            <setter property="IsSynchronizedWithCurrentItem" value="True" />                            
                            <setter property="AllowDrop" value="True" />
                            <setter property="IsDropDownOpen" value="true" />                            
                        </Style>
                    </datagridcomboboxcolumn.editingelementstyle>
                </datagridcomboboxcolumn>
                <datagridtextcolumn loc:translate.uid="1659" header="{loc:Translate الكمية الكبرى}" width="Auto" binding="{Binding quantity}" xmlns:loc="#unknown" />
                <datagridtextcolumn loc:translate.uid="1660" header="{loc:Translate الكمية الصغرى}" width="Auto" binding="{Binding Unit}" xmlns:loc="#unknown" />                
                <datagridtextcolumn loc:translate.uid="1662" header="{loc:Translate   ضريبة}" width="Auto" binding="{Binding Tax}" xmlns:loc="#unknown" />
                <datagridtextcolumn loc:translate.uid="1663" header="{loc:Translate  خصم اول}" width="Auto" binding="{Binding Discount1}" xmlns:loc="#unknown" />
                <datagridtextcolumn loc:translate.uid="1664" header="{loc:Translate  خصم تانى}" width="Auto" binding="{Binding Discount2}" xmlns:loc="#unknown" />
                <datagridtextcolumn loc:translate.uid="1665" header="{loc:Translate  خصم ثالث}" width="Auto" binding="{Binding Discount3}" xmlns:loc="#unknown" />
                <datagridtextcolumn loc:translate.uid="1667" header="{loc:Translate   الجملة}" width="*" binding="{Binding Total}" isreadonly="True" xmlns:loc="#unknown" />
            </datagrid.columns>
        </datagrid>



My C# Code
C#
private void FillDataSources()
        {
            this.DT_DataSource_AllMedicine = Cls_MedicineController.SelectAllActiveMedecines();
            this.DT_DataSource_AllOrderItems = Cls_PurchaseController.SelectAllOrders();            
            this.DT_DataSource_AllSuppliers = Cls_PurchaseController.SelectAllSupplierCompany();
        }

        private void SetUpOrderItems()
        {
            DataColumn DC = new DataColumn("Index", typeof(int));
            this.DT_DataSource_AllOrderItems.Columns.Add(DC);
            this.DT_DataSource_AllOrderItems.Columns["Index"].AutoIncrement = true;
            this.DT_DataSource_AllOrderItems.Columns["Index"].AutoIncrementStep = 1;
            this.DT_DataSource_AllOrderItems.Columns["Index"].AutoIncrementSeed = 1;            
        }

        private void SetDefaults()
        {
            this.DT_DataSource_AllOrderItems.Columns["quantity"].DefaultValue = 0;
            this.DT_DataSource_AllOrderItems.Columns["Unit"].DefaultValue = 0;
            this.DT_DataSource_AllOrderItems.Columns["Tax"].DefaultValue = 0;
            this.DT_DataSource_AllOrderItems.Columns["Discount1"].DefaultValue = 0;
            this.DT_DataSource_AllOrderItems.Columns["Discount2"].DefaultValue = 0;
            this.DT_DataSource_AllOrderItems.Columns["Discount3"].DefaultValue = 0;
            this.DT_DataSource_AllOrderItems.Columns["Total"].DefaultValue = 0;
            this.DT_DataSource_AllOrderItems.Columns["Med_ID"].DefaultValue = 1;
        }

        private void FillDataGrid()
        {
            this.DT_DataSource_AllOrderItems = Cls_PurchaseController.SelectAllOrderItems(this.CurrentOrderID);
            this.SetUpOrderItems();
            this.SetDefaults();
            DataGridComboBoxColumn COL = ((DataGridComboBoxColumn)(this.DG_Order.Columns[2]));
            COL.ItemsSource = this.DT_DataSource_AllMedicine.DefaultView;
            DataGridComboBoxColumn COL1 = ((DataGridComboBoxColumn)(this.DG_Order.Columns[1]));
            COL1.ItemsSource = this.DT_DataSource_AllMedicine.DefaultView;
            this.DG_Order.ItemsSource = this.DT_DataSource_AllOrderItems.DefaultView;
            //this.DG_Order.DataContext = this.DT_DataSource_AllOrderItems;
        }

        private void FillItemsSource()
        {
            this.FillDataSources();
            this.FillDataGrid();
            this.DT_DataSource_AllOrderItems.Rows.Add(this.DT_DataSource_AllOrderItems.NewRow());
            this.Cmx_SupCompany.ItemsSource = this.DT_DataSource_AllSuppliers.DefaultView;
            this.Cmx_Orders.ItemsSource = this.DT_DataSource_AllOrders.DefaultView;            
        }
Posted

1 solution

Use a virtualizing stack panel!

http://vbcity.com/blogs/xtab/archive/2009/12/15/wpf-using-a-virtualizingstackpanel-to-improve-combobox-performance.aspx[^]

This will VASTLY improve the performance of the WPF combo box if you have lots of items - like hundreds of times faster :)

With a virtualizing stack panel as the items panel you'll be able to use hundreds of thousands of items with ease:

XML
<ComboBox ItemsSource="{Binding}"gt;
      <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
          <VirtualizingStackPanel />
        </ItemsPanelTemplate>
      </ComboBox.ItemsPanel>
    </ComboBox>
 
Share this answer
 
v3
Comments
Yasser El Shazly 13-Oct-11 6:18am    
in my Example i have DataGridComboBox Column not ComboBox
Yasser El Shazly 13-Oct-11 6:20am    
how the solution will be different
Dave Kerr 13-Oct-11 6:39am    
Use these attributes in the XAML datagrid definition:

EnableRowVirtualization="True" EnableColumnVirtualization="True"
VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"

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