如何在AutoCompleteStringCollection中添加大量产品 [英] How to add large number of Products in AutoCompleteStringCollection

查看:123
本文介绍了如何在AutoCompleteStringCollection中添加大量产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我有一个网格视图,其中显示了产品的详细信息.首先要获取详细信息,我必须选择一个产品.因此,在行的第一个单元格中输入字母以获取产品.要在该单元格中获取产品作为清单我是
使用AutoCompleteStringCollection.页面加载时,我正在填充此AutoCompleteStringCollection

In My project i have a gridview in which i am showing productdetails.For Getting Details firstly i have to select a product.So in the first cell of row i type the alphabets to get the products.To get products in the cell as a list i am
using AutoCompleteStringCollection.On page load i am filling this AutoCompleteStringCollection

scAutoCompletedgv.Clear();
string StrSel ="";
if (SelectedCompany.Count == 0)
    StrSel = "select productname from products order by productname";

DataTable dt = new DataTable();
dt = ObjSql.Select(StrSel);
if (dt != null && dt.Rows.Count > 0)
{
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        scAutoCompletedgv.Add(dt.Rows[i]["productName"].ToString());
    }
}


我在datagrid视图的EditingControlShowing事件上使用此事件,如下所示


and i am using this on datagrid views EditingControlShowing event like below

//Because of this Code I am getiing ProductNames as a dropdown list in the cell of DataGridView
            if (gvProduct.CurrentCellAddress.X == 0)
            {
                TextBox txt = e.Control as TextBox;
                txt.AutoCompleteCustomSource = scAutoCompletedgv;
                txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
            } 


通过此代码,我在datagrid视图的第一个单元格中获得了产品名称列表,如dropdownlist
但是,由于有超过2万种产品,因此在AutoCompleteStringCollection中添加产品需要花费大量时间,并且那时我的应用程序被挂起...有什么办法可以在很短的时间内附加这么多产品?
请帮助


by this code i am getting a list of product name in the first cell of datagrid view like a dropdownlist
But as there are more than 20000 products,adding products in AutoCompleteStringCollection takes so much time and my application gets Hanged at that time...Is there any way to attach so many product within very short time?
Pls Help

推荐答案

最好等待用户输入一些文本.这样,您可以缩小集合中所需项目的列表.让用户至少输入1个(或什至2个或3个)字符,然后稍等片刻.之后,执行查询并填充集合.这样,查询结果将被过滤到相关条目中,从而使其变得更小,并且由于它表示数据库中的实际更改,因此也是最新的.

另一种方法是使用线程/后台工作程序获取数据,以便表单在加载期间保持响应状态.

祝你好运!
It might be better to wait for the user to enter some text. This way you can narrow the list of items you need in the collection. Let the user at least enter 1 (or even 2 or 3) characters and wait a little while. After that, execute the query and fill the collection. This way the result of the query is filtered to relevant entries which makes it a lot smaller and is also up to date because it represents actual changes in the database.

Another way would be to use a thread/background worker to get the data so the form stays responsive during load.

Good luck!


这篇关于如何在AutoCompleteStringCollection中添加大量产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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