Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

ArrayToListbox - Add an array of strings to a ListBox or ComboBox

Total Hit ( 4354)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
  hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  lParam As Any) As Long
Private Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" _
  (ByVal hwndLock As Long) As Long

Private Const LB_ADDSTRING = &H180
Private Const LB_RESETCONTENT = &H184
Private Const CB_ADDSTRING = &H143
Private Const CB_RESETCONTENT = &H14B

' Add an array of string to a listbox or combo box
' using API functions, and optionally clearing it first
' This procedure is faster than the one based on AddItem methods,
' especially with ComboBox controls, and reduces flickering
'
' FIRST and LAST indicate which portion of the array
' should be considered; they default to the first
' and last element, respectively

Sub ArrayToListBox(ctrl As Object, arr As Variant, Optional clearIt As Boolean, _
  Optional ByVal First As Variant, Optional ByVal Last As Variant)
  Dim msgReset As Long
  Dim msgAdd As Long
  Dim hWnd As Long
  Dim index As Long
  
  If TypeOf ctrl Is ListBox Then
    msgReset = LB_RESETCONTENT
    msgAdd = LB_ADDSTRING
  ElseIf TypeOf ctrl Is ComboBox Then
    msgReset = CB_RESETCONTENT
    msgAdd = CB_ADDSTRING
  Else
    ' none of the above, exit
    Exit Sub
  End If
  
  If IsMissing(First) Then First = LBound(arr)
  If IsMissing(Last) Then Last = UBound(arr)
  
  ' disable redrawing
  hWnd = ctrl.hWnd
  LockWindowUpdate hWnd
  
  ' clear control if requested
  If clearIt Then
    SendMessage hWnd, msgReset, 0, 0
  End If
  
  ' add all items in the array
  For index = First To Last
    SendMessage hWnd, msgAdd, 0, ByVal CStr(arr(index))
  Next
  ' re-enable redrawing
  LockWindowUpdate 0
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.