C#Winform中的自动完成文本框速度很慢 [英] Autocomplete Textbox Very Slow in C# Winform

查看:474
本文介绍了C#Winform中的自动完成文本框速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在我的项目中,我使用的是自动填充文本框。我在自动填充文本框中绑定电话号码与数据库。我的桌子上有超过500条记录(电话没有表格)。它在我的方法中加载非常慢。如何提高自动完成的性能。如果有人知道这个PLZ的解决方案就回复我...



谢谢&问候

<前lang =c#> OleDbCommand cmd1 = null ; OleDbCommand cmd11 = null ;
namesCollection1.Clear();
cmd1 = new OleDbCommand( select *来自InvoiceDetails,Con);
OleDbDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
if (!namesCollection1.Contains(dr1 [ 4 ]。ToString()))
{
namesCollection1.Add(dr1 [ 4 ]的ToString());
}
}
cmd1.Dispose();
dr1.Dispose();


cmd11 = new OleDbCommand( select * from CustomerDetails,Con);
OleDbDataReader dr11 = cmd11.ExecuteReader();
while (dr11.Read())
{
if (!namesCollection1.Contains(dr11 [ 11 ]。ToString()))
{
namesCollection1.Add(dr11 [ 11 ]的ToString());
}
}
cmd11.Dispose();
dr11.Dispose();

PhoneNoText.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
PhoneNoText.AutoCompleteSource = AutoCompleteSource.CustomSource;
PhoneNoText.AutoCompleteCustomSource = namesCollection1;







添加OP发布的代码块作为评论 - Original Griff [ / edit]

解决方案

加快速度永远不是做到这一点的解决方案 - 这是一个需要相当多感觉的迭代过程。



要做的第一件事就是准确计算正在发生的事情的时间,这样你就可以了解各个部件的速度或速度,以及每次变化实际上有多大差异。



所以:看看秒表课程

秒表sw1 = 秒表(); 
sw1.Start();
... 执行代码到时间
sw1.Stop();
Console.WriteLine( Stopwatch1:{0,06},sw1.ElapsedMilliseconds) ;



这为您提供了工作的基础。

运行六次,以便您稍后比较一小部分值。



然后,首先只返回你实际需要的SQL数据:

  SELECT  MyColumn  FROM  InvoiceDetails 


$ b $效率更高b

  SELECT  *  FROM  InvoiceDetails 

因为它只返回您实际需要的数据。在一种情况下,您将返回至少十个您不想要或不使用的列!



再次多次,并在两种情况下显示结果。


Hi Everyone,

In my project i m using autocomplete textbox. i m binding the Phone no from database in autocomplete textbox. I have more than 500 records in my table (phone no table). it loading very slow in my method. how can i increase performance for autocomplete. if any one know solution for this plz just reply me...

thanks & regards

OleDbCommand cmd1 = null; OleDbCommand cmd11 = null;
namesCollection1.Clear();
cmd1 = new OleDbCommand("select * from InvoiceDetails", Con);
OleDbDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
    if (!namesCollection1.Contains(dr1[4].ToString()))
    {
        namesCollection1.Add(dr1[4].ToString());
    }
}
cmd1.Dispose();
dr1.Dispose();


cmd11 = new OleDbCommand("select * from CustomerDetails", Con);
OleDbDataReader dr11 = cmd11.ExecuteReader();
while (dr11.Read())
{
    if (!namesCollection1.Contains(dr11[11].ToString()))
    {
        namesCollection1.Add(dr11[11].ToString());
    }
}
cmd11.Dispose();
dr11.Dispose();

PhoneNoText.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
PhoneNoText.AutoCompleteSource = AutoCompleteSource.CustomSource;
PhoneNoText.AutoCompleteCustomSource = namesCollection1;




[edit]Added code block posted by OP as comment - Original Griff[/edit]

解决方案

Speeding things up is never a "do this" solution - it's an iterative process that needs a fair amount of "feel".

The first thing to do is to time exactly what is happening, so you get a feel for how fast or slow the various parts are, and how much difference each change you make actually does.

So: look at the Stopwatch class

Stopwatch sw1 = new Stopwatch();
sw1.Start();
... do code to time
sw1.Stop();
Console.WriteLine("Stopwatch1: {0,06}", sw1.ElapsedMilliseconds);


This gives you a base to work from.
Run that half a dozen times so you have a small range of values to compare later.

Then, start by only returning the data from SQL that you actually need:

SELECT MyColumn FROM InvoiceDetails

Is a lot more efficient than

SELECT * FROM InvoiceDetails

Because it only returns the data you actually need. In one case you are returning at least ten columns that you don't want or use!

Time that again several times, and show me the results in both cases.


这篇关于C#Winform中的自动完成文本框速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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