ListBox Ocx

Purpose

Creates an Ocx ListBox control in the current active form, window, or dialog.

Syntax

Ocx ListBox name = [text$] [, id], x, y, w, h[, style%]

text$:control text
id%:control identifier
x, y, w, h:iexp
style%:the control styles

Description

The control is a rectangle containing a list of strings (such as filenames) from which the user can select.

To add or delete items in a ListBox control, use the AddItem or RemoveItem method. Set the List, ListCount, and ListIndex properties to enable a user to access items in the ListBox.

If no item is selected, the ListIndex property value is -1. The first item in the list is ListIndex = 0, and the value of the ListCount property is always one more than the largest ListIndex value.

The ListBox Ocx control has the following properties, methods, and events.

Properties

Appearance | BackColor | ForeColor | BorderStyle | Columns | DisableNoScroll | Enabled | Font | FontBold | FontItalic | FontStrikethru | FontUnderline | FontName | FontSize | Height, Width | HelpContextID | hWnd | Index | IntegralHeight |ItemData | Left, Top | List | ListCount | ListIndex | MouseCursor | MouseIcon | MousePointer | MultiSelect | Name | NewIndex | Parent | Scrollbars | Selected | Sorted | TabStop | Tag | Text | ToolTiptext | TopIndex | Visible | WhatsThisHelpID

The SelCount property is missing. This property is particularly useful when users can make multiple selections. There is no alternative then to use the LB_GETSELCOUNT message as shown in the example.

Methods

AddItem | Clear | Find | FindExact | FindNext | InsertItem | Move | Refresh | RemoveItem | SetFocus | SetFont | TextHeight | TextWidth | ZOrder

Events

Click | DblClick | GotFocus | LostFocus | KeyDown, KeyUp | KeyPress | MouseDown | MouseUp | MouseMove

Example

Form frm = "Listbox", , , 500, 400

Ocx ListBox lb1 "", 0, 0, 250, 200

.MultiSelect = 1

Ocx ListBox lb2 = "", 250, 0, 250, 200

Ocx Command cmd1 = "Add to 2", 100, 220, 80, 24

cmd1.Enabled = False

Dim i%

For i = 0 To Screen.FontCount - 1

lb1.AddItem Screen.Fonts(i)

Next i

Do

Sleep

Until Me Is Nothing

 

Sub cmd1_Click ()

Dim i%

lb2.Clear       ' Clear all items from the list.

For i = 0 To lb1.ListCount - 1

If lb1.Selected(i) Then

lb2.AddItem lb1.List(i)

End If

Next i

End Sub

 

Sub lb1_Click

' The missing ListBox property: SelCount:

Dim SelCount% = SendMessage(lb1.hWnd, LB_GETSELCOUNT, 0, 0)

If SelCount = 0 && cmd1.Enabled

cmd1.Enabled = False

Else If SelCount > 0 && cmd1.Enabled = False

cmd1.Enabled = True

EndIf

EndSub

See Also

Ocx, OcxOcx

Animation, CheckBox, ComboBox, Command, CommDlg, Form, Frame, Image, ImageList, Label, ListView, MonthView, Option, ProgressBar, RichEdit, Scroll, Slider, StatusBar, TabStrip, TextBox, Timer, TrayIcon, TreeView, UpDown

{Created by Sjouke Hamstra; Last updated: 07/10/2017 by James Gaite}