				ComboBoxLB

Last changed at 19-april-2001.




Sub's, Properties and Events

============================================================

Sub's:

============================================================

Sub About()

Gives information about the version and the creator of the combobox.

----------------

Sub AddList(strItem As String)

Adds a list to the combobox.

----------------

Sub FillComboBoxMultiColumn(dbDatabase As Database, strSelectQuery As String)

The sub FillComboBoxMultiColumn fills the combobox.
Before the combobox is filled it is cleared.

============================================================

Properties:

============================================================

Property BackColorNormal() As OLE_COLOR

Returns/sets the background color of an item in the listbox.

----------------

Property BackColorSelected() As OLE_COLOR

Returns/sets the background color of a selected item in the listbox.

----------------

Property BoundColumn() As Integer

Returns/sets the bound column which contains a unique number added to the combobox.
The first column starts with 0.

----------------

Property Column(intColumn As Integer)

Returns the text in a column specified by intColumn. If intColumn is 0 then the 
first column will be returned.

----------------

Property ColumnCount() As Integer

Returns/sets the number of columns. The minimum is one column.

----------------

Property ColumnWidths(strColumnWidths As String)

Sets the width of the columns.
This property can be set in code only.

----------------

Property Enabled() As Boolean

Returns/sets a value that determines whether an object can respond to 
user-generated events.

----------------

Property ForeColorNormal() As OLE_COLOR

Returns/sets the foreground color of an item in the listbox.

----------------

Property ForeColorSelected() As OLE_COLOR

Returns/sets the foreground color of a selected item in the listbox.

----------------

Property ListIndex() As Long

Returns/sets the index of the currently selected item in the control.

----------------

Property ListRows() As Integer

Returns/sets the maximum number of rows in the combobox list. The minimum is two rows and the maximum is eight rows.

----------------

Property ListWidth() As Integer

Returns/sets the width of the combobox drop-down list. If set to -1 then the width of the drop-down list will be the same as the combobox width.

----------------

Property Text() As Variant

Returns the text contained in the combobox.

----------------

Property Value() As Variant

Selects/gets the boundcolumn of the currently selected item.

============================================================

Events:

============================================================

After_Update: The same event as in Microsoft Access.
KeyDown
KeyPress
KeyUp

============================================================
============================================================
============================================================
============================================================
============================================================

Examples:

Start a new project and reference the library: Microsoft DAO 3.51 Object Library
Select the form and set the ScaleMode of the form to 1 - Twip.



Dim db As Database
Dim strSQL As String



Private Sub Form_Load()
   
   Dim strPathData As String

   strPathData = App.Path
   If Not Right(strPathData, 1) = "\" Then
      strPathData = strPathData & "\"
   End If
   strPathData = strPathData & "datalang.mdb"
   
   Set db = OpenDatabase(strPathData)    ' get database

End Sub



Private Sub Form_Unload(Cancel As Integer)
   db.Close
End Sub





Example 1:
Fill the combobox with a select query.

In the properties window of combobox ComboBoxLB1:
BoundColumn = 1
ColumnCount = 3
ListRows = 8
ListWidth = 3000
Width =2310

In code:
strSQL = "SELECT DISTINCT Statement, Number, FkLanguages FROM DataTable WHERE FkLanguages = 17 ORDER BY Statement;"

' set this property always, it must be set in code
ComboBoxLB1.ColumnWidths = "1485;750"    ' last column is set to the ListWidth - 1485 - 750   
ComboBoxLB1.ColumnLineForeColor = &H404040    ' comment this line to get the default color
ComboBoxLB1.FillComboBoxMultiColumn db, strSQL
  
NOTE: always use DISTINCT in the sql string. Hum maybe not.





Example 2:
Add a predefined list to the combobox.

In the properties window of combobox ComboBoxLB1:
BoundColumn = 0
ColumnCount = 2
ListRows = 8
ListWidth = -1

In code:
ComboBoxLB1.ColumnWidths = ""
ComboBoxLB1.ColumnLineForeColor = &HFF0000
ComboBoxLB1.AddList "1;first;2;second;3;third"





Known bugs:

 - The listbox will not hide when clicked on form or other application.
   
   Solution:
   Workaraound.
   You can hide the listbox when clicked on the form by adding this code to the sub
   Add a field txtAField to the form.
   Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   ' this will hide the listbox part of the combobox when clicked on the form

      Dim ctl As Control
   
      Set ctl = Screen.ActiveControl
   
      txtAField.SetFocus    ' a field behind a button
      If ctl.Name = "ComboBoxLB1" Then
         Select Case ctl.Index
            Case 0
               ComboBoxLB1(0).SetFocus    ' this is the first combobox
            Case 1
               ComboBoxLB1(1).SetFocus    ' this is the second combobox
         End Select
      End If

   End Sub
   In this situation i have a form with two comboboxes in an array with indexes of 0 and 1.

 - When the combobox is open (listbox is visible) and ESC is pressed the key is passed to
   the application when a button has the Cancel property set to True.
   It should be eaten by the combobox.

   Solution:
   Not available.

 - The boundcolumn must be an unique number, not an unique string.

   Solution:
   Solved in second release. The boundcolumn can also be an unique string now.
   For instance when you have only one column in the combobox filled with strings.



This control is created by Patrick van Olderen.
http://www.home.zonnet.nl/PatrickO/




Using this control is for your own risk. I do not take any responsibility for harm done by this control.