|
-
Jul 11th, 2008, 01:33 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Auto Complete Problem
In my Customer profile form, i have this Combobox2 where i add items using the following code and have set the Auto Complete source to list items.
Code:
Private Sub newCust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wrs.Open("select name from customer order by cuid", Module1.db, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
While Not wrs.EOF
ComboBox2.Items.Add(wrs.Fields!name.Value)
wrs.MoveNext()
End While
wrs.Close()
End Sub
Now whenever i open Customer profile form, it takes around 5-8 seconds to load all the names. How can i do this faster ?
-
Jul 11th, 2008, 01:47 AM
#2
Re: [2005] Auto Complete Problem
When you have autocomplete enabled the ComboBox does some work after you add an item. Not only that, it does some work for each item in the control after you add each item, so the amount of work done grows geometrically with the number of items you add. If you add 1 item then 1 unit of work is done. If you add 2 items then 3 units of work is done. If you add 3 items then 6 units of work is done. If you add 10 items then 55 units of work are done. Etc. What you need to do is ensure that this work is only done after the last item is added, so it's only done once for each item. To do that you call BeginUpdate on the ComboBox before you start and then EndUpdate when you're done.
That said, you should get rid of that ADO code and use ADO.NET. Then you could populate a DataTable and bind the data and this would never have been an issue.
-
Jul 11th, 2008, 02:20 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] Auto Complete Problem
Sorry did not understand !
-
Jul 11th, 2008, 03:58 AM
#4
Re: [2005] Auto Complete Problem
How hard did you try?
What you need to do is ensure that this work is only done after the last item is added, so it's only done once for each item. To do that you call BeginUpdate on the ComboBox before you start and then EndUpdate when you're done.
That's the part that matters. The rest is by way of explanation.
-
Jul 12th, 2008, 01:24 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] Auto Complete Problem
I have done this, but it takes as much time as before.
vb Code:
Private Sub newCust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load wrs.Open("select name from customer order by cuid", Module1.db, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic) While Not wrs.EOF ComboBox2.BeginUpdate() ComboBox2.Items.Add(wrs.Fields!name.Value) ComboBox2.EndUpdate() wrs.MoveNext() End While wrs.Close() End Sub
-
Jul 12th, 2008, 01:42 AM
#6
Re: [2005] Auto Complete Problem
The whole point of my post was that you want to make sure that whatever work the control is doing is only done once. To that end, do you really think that you would call BeginUpdate and EndUpdate over and over, once for each item? If you want the work done once then that would suggest that you only call those methods once.
What you need to do is ensure that this work is only done after the last item is added, so it's only done once for each item. To do that you call BeginUpdate on the ComboBox before you start and then EndUpdate when you're done.
Last edited by jmcilhinney; Jul 12th, 2008 at 01:48 AM.
-
Jul 13th, 2008, 09:50 AM
#7
Thread Starter
Hyperactive Member
Re: [2005] Auto Complete Problem
Yes sir, i got what u said will use the beginupdate and endupdate everytime i add a new record to it.
Can i store the this array collection in some string while starting the application and then just apply it to my combobox everytime i open this form ? how can i do this ?
-
Jul 16th, 2008, 05:45 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] Auto Complete Problem
can anybody plz tell me how to store a collection of names in an array ?
-
Jul 16th, 2008, 06:12 AM
#9
Re: [2005] Auto Complete Problem
Code:
Dim s() As String = New String() {"one", "two", "three"}
For x As Integer = s.Length To 10
Array.Resize(s, s.Length + 1)
s(s.Length - 1) = x.ToString
Next
ComboBox1.Items.AddRange(s)
-
Jul 18th, 2008, 02:02 AM
#10
Thread Starter
Hyperactive Member
Re: [2005] Auto Complete Problem
Mr. dbasnett, i want to store the collection of customer's names in a string or array at the start of my application. Then i will use this string or array to populate the combobox wherever required. In your code how do i add all the names of the customers to 's' ?
-
Jul 18th, 2008, 06:28 AM
#11
Re: [2005] Auto Complete Problem
s() would be the string array of customer names.
-
Jul 18th, 2008, 06:36 AM
#12
Thread Starter
Hyperactive Member
Re: [2005] Auto Complete Problem
ya but how do i add the names to it using my codes in #1 ?
-
Jul 21st, 2008, 10:08 AM
#13
Thread Starter
Hyperactive Member
Re: [2005] Auto Complete Problem
Mr. Nett,
I am waiting....
-
Jul 21st, 2008, 10:13 AM
#14
Re: [2005] Auto Complete Problem
think how you would incorporate my loop into your loop?
-
Jul 22nd, 2008, 09:36 AM
#15
Thread Starter
Hyperactive Member
Re: [2005] Auto Complete Problem
I am here to solve the problem i am facing with the s/w which is installed for my business, and not to THINK and learn VB.net and make my career as a developer !
-
Jul 22nd, 2008, 10:56 AM
#16
Re: [2005] Auto Complete Problem
I am here to help with your code, not write it for you.
Code:
Private Sub newCust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wrs.Open("select name from customer order by cuid", Module1.db, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
ComboBox2.BeginUpdate()
While Not wrs.EOF
ComboBox2.Items.Add(wrs.Fields!name.Value)
wrs.MoveNext()
End While
ComboBox2.EndUpdate()
wrs.Close()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|