[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 ?
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.
Re: [2005] Auto Complete Problem
Sorry did not understand !
Re: [2005] Auto Complete Problem
How hard did you try?
Quote:
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.
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
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.
Quote:
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.
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 ?
Re: [2005] Auto Complete Problem
can anybody plz tell me how to store a collection of names in an array ?
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)
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' ?
Re: [2005] Auto Complete Problem
s() would be the string array of customer names.
Re: [2005] Auto Complete Problem
ya but how do i add the names to it using my codes in #1 ?
Re: [2005] Auto Complete Problem
Mr. Nett,
I am waiting....
Re: [2005] Auto Complete Problem
think how you would incorporate my loop into your loop?
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 !
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