|
List Box is a control in visual basic 6 which is used to display various items available where a user can select one or more items depending on the Multiselect property set from the properties panel. The items in a list box can be added at design time from the list property from the properties panel or Populate Data To Listbox From Database at run time. We can also use its style property to set it to standard or checkbox where we can have check box against each item. The List Box also supports various events important of which are discussed here.
Important properties of a List box
- Multiselect: This property is used if we want to select more than one item from the list. The other options available under this property are: None, Simple and Extended.
- Sorted: This property is used if we want the list items to be in a sorted order or not.
- Style: The options available under this property are Standard and Checkbox which displays a check box against each list.
Important events of a List box
- Click: This is the default event of a List box which is executed when we click on any item.
- Double Click: This event is executed when we double click on any item.
- Key press: This event is executed when any key is pressed on the list box.
- Scroll: This event gets executed when we scroll in the listbox.
‘Here is the Module
Option Explicit
Public Con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public rs2 As New ADODB.Recordset
Public sql As String
Public query As String
Public Sub Connection()
Set Con = New ADODB.Connection
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Persist Security Info=False"
End Sub
' add the following code to the load event of form1
' list1 is the listbox on form1......
'call the connection
Connection
sql = "SELECT (investigation ) As Investigations FROM investigation order by investigation asc "
Set rs = New ADODB.Recordset
rs.Open sql, Con, adOpenDynamic, adLockOptimistic
Do While Not rs.EOF
List1.AddItem UCase(rs!Investigations)
rs.MoveNext
Loop
rs.Close: Set rs = Nothing
0 comments:
Post a Comment