Results 1 to 16 of 16

Thread: [RESOLVED] [2005] Auto Complete Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Resolved [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 ?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Auto Complete Problem

    Sorry did not understand !

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Auto Complete Problem

    I have done this, but it takes as much time as before.

    vb Code:
    1. Private Sub newCust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         wrs.Open("select name from customer order by cuid", Module1.db, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
    3.         While Not wrs.EOF
    4.             ComboBox2.BeginUpdate()
    5.             ComboBox2.Items.Add(wrs.Fields!name.Value)
    6.             ComboBox2.EndUpdate()
    7.             wrs.MoveNext()
    8.         End While
    9.         wrs.Close()
    10. End Sub

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    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 ?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Auto Complete Problem

    can anybody plz tell me how to store a collection of names in an array ?

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

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

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Auto Complete Problem

    s() would be the string array of customer names.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Auto Complete Problem

    ya but how do i add the names to it using my codes in #1 ?

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Auto Complete Problem

    Mr. Nett,
    I am waiting....

  14. #14
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Auto Complete Problem

    think how you would incorporate my loop into your loop?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    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 !

  16. #16
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width