Copy one combo list to another 
Author Message
 Copy one combo list to another

I've got a combo box on my form, and I need to load 508 items in to the box
at run time. The data is being loaded from a binary file with the help of a
class module that I wrote. My problem is this, I need to create an array of
9 or 10 of these combo boxes with all the 508 items. Does anyone know if
there is a way to copy the contents of one combo box to another? I can
reload the stuff from the files for each box, but that is very time
consuming.

Dale Atkin



Wed, 31 Jan 2001 03:00:00 GMT  
 Copy one combo list to another
Interesring, very, very interestion, I hadn't thought of trying that. I
inserted some timer code in my code, and the whole procedure on my side
(Pentium 200MHz 64MB RAM) is taking as you said, about 6seconds (well
5.990000000002)  So reading the stuff from a file was not as much of a time
concern as I though it might be, still, I think it would be faster if there
was a way of saying "Use that combo-box list as a basis for this new box"

Is there a way when dealing with arrays of combo boxes to have VB copy the
list of the original combo box to the new combo box?

Dale Atkin



Wed, 31 Jan 2001 03:00:00 GMT  
 Copy one combo list to another
Dale,
For even more performance boost (a more accurate timer too)  try the code
below.
SendMessage is MUCH faster than AddItem (additem Must sendmessage ;-):
Also, to speed things up shove all the text into an array and then use that
to populate the Cbs. Accesssing A cb.List(I) each time will be SLOW!!!

This runs in 1.16 seconds on my machine.  D Copperheads code ran in 2.25
seconds. (so it will probably run in about 3.1 seconds on yours).
NN

Option Explicit

'For the timer
Private Declare Function GetTickCount& Lib "kernel32" ()

'To prevent repaint
Private Declare Function LockWindowUpdate& Lib "user32" (ByVal hwndLock As
Long)

'To do all the work
Private Declare Function SendMessageByString& Lib "user32" Alias
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As
Long, ByVal lParam As String)
'The nature of the work
Private Const CB_ADDSTRING& = &H143

Private Sub Command1_Click()
    Dim i As Long, x As Integer, TotalCbo%
    Dim St As Long, Fs As Long, lngLock As Long, lngAdd As Long
    Me.Cls
    St = GetTickCount
    TotalCbo = 9
    For x = 0 To TotalCbo
        With Combo1(x)
        'The LockWindowUpdate does not boost like it does with Listboxes ???
            lngLock = LockWindowUpdate(.hwnd)
            For i = 1 To 508
               lngAdd = SendMessageByString(.hwnd, CB_ADDSTRING, i, ByVal
"Item# " & i)
            Next
         lngLock = LockWindowUpdate(0&)
        DoEvents
        .ListIndex = x
        End With
    Next 'x
    Fs = GetTickCount

    Me.Print Format((Fs - St) / 1000, "###.####") & " seconds"
    'elased time of process
End Sub

Quote:

>Interesring, very, very interestion, I hadn't thought of trying that. I
>inserted some timer code in my code, and the whole procedure on my side
>(Pentium 200MHz 64MB RAM) is taking as you said, about 6seconds (well
>5.990000000002)  So reading the stuff from a file was not as much of a time
>concern as I though it might be, still, I think it would be faster if there
>was a way of saying "Use that combo-box list as a basis for this new box"

>Is there a way when dealing with arrays of combo boxes to have VB copy the
>list of the original combo box to the new combo box?

>Dale Atkin




Wed, 31 Jan 2001 03:00:00 GMT  
 Copy one combo list to another
Since you have a combobox array, why not use a loop to load all the combos
with each entry:

        While (loop to read all the entries from the file)
           sItem = (stuff from the file)
           For i = 0 To 9
              Combo1(i).AddItem sItem
           Next i
        Wend

Lee Weiner
weiner AT fuse DOT net


Quote:

>I've got a combo box on my form, and I need to load 508 items in to the box
>at run time. The data is being loaded from a binary file with the help of a
>class module that I wrote. My problem is this, I need to create an array of
>9 or 10 of these combo boxes with all the 508 items. Does anyone know if
>there is a way to copy the contents of one combo box to another? I can
>reload the stuff from the files for each box, but that is very time
>consuming.

>Dale Atkin




Fri, 09 Feb 2001 03:00:00 GMT  
 Copy one combo list to another

Quote:
>Since you have a combobox array, why not use a loop to load all the combos
>with each entry:

Cuz it's slow :  )


Sat, 10 Feb 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. One-Click / Mouse-over on Combo List - subclass combo question

2. Help: One-Click / Mouse-over on Combo List - subclass combo question

3. How to copy the contents from one combo box to another

4. Fill Combo List using Criteria selected in another Combo List

5. Fill Combo List using Criteria selected in another Combo List

6. Setting/copying the items in a combo's list

7. Changing fonts on one entry in a list/combo box

8. Need to copy tasks from one project to another one

9. Combo date value set by code gets ignored by combo's list when opened

10. Listing all tables or queries in a list/combo box

11. How to list macro names in a combo box or a list box

12. How to list macro names in a combo box or a list

 

 
Powered by phpBB® Forum Software