在ComboBox中进行简单搜索,其中填充了非常大的项目 [英] Simple Search in ComboBox Filled With Very Large items Number

查看:73
本文介绍了在ComboBox中进行简单搜索,其中填充了非常大的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我在WPF Windows窗体中有一个数据网格,此数据网格中有一个DatagridComboBoxColumn,此组合框填充范围为10000至20000,项目用户可以通过此组合框从它们中选择任意一个.在组合框中键入,自动下拉"被打开,但是问题是,因为从数据表出价到组合框的项目数量很大,自动下拉需要一些时间才能打开,因此需要在组合中进行搜索盒子是如此复杂,有没有什么建议可以使它变得更容易并满足用户越来越多的需求

在高级感谢

我的XML代码

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

<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>




我的C#代码




My C# Code

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;            
        }

推荐答案

使用虚拟化堆栈面板!

http://vbcity. com/blogs/xtab/archive/2009/12/15/wpf-using-a-virtualizingstackpanel-to-improve-combobox-performance.aspx [
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:

<ComboBox ItemsSource="{Binding}"gt;

      <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
          <VirtualizingStackPanel />
        </ItemsPanelTemplate>
      </ComboBox.ItemsPanel>
    </ComboBox>


这篇关于在ComboBox中进行简单搜索,其中填充了非常大的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆