ListBox (Control: propiedades, métodos y eventos)

Propiedades

Application BaseClass BorderColor
BoundColumn BoundTo Class
ClassLibrary ColorScheme ColorSource
ColumnCount ColumnLines ColumnWidths
Comment ControlSource DisabledBackColor
DisabledForeColor DisabledItemBackColor DisabledItemForeColor
DisplayValue DragIcon DragMode
Enabled FirstElement FontBold
FontCondense FontExtend FontItalic
FontName FontOutline FontShadow
FontSize FontStrikeThru FontUnderLine
Height HelpContextID IncrementalSearch
IntegralHeight ItemBackColor ItemData
ItemForeColor ItemIDData ItemTips
Left List ListCount
ListIndex ListItem ListItemID
MouseIcon MousePointer MoverBars
MultiSelect Name NewIndex
NewItemID NullDisplay NumberOfElements
OLEDragMode OLEDragPicture OLEDropEffects
OLEDropHasData (Propiedad) OLEDropMode Parent
ParentClass Picture RightToLeft
RowSource RowSourceType Selected
SelectedID ItemBackColor, ItemForeColor (Propiedades) ItemBackColor, ItemForeColor (Propiedades)
Sorted SpecialEffect StatusBarText
TabIndex TabStop Tag
TerminateRead ToolTipText Top
TopIndex TopItemID Value
Visible WhatsThisHelpID Width

Eventos

Click DblClick Destroy
DragDrop DragOver Error
ErrorMessage GotFocus Init
InteractiveChange KeyPress LostFocus
Message MiddleClick Event MouseDown
MouseEnter MouseLeave MouseMove
MouseUp MouseWheel OLECompleteDrag
OLEDragDrop OLEDragOver OLEGiveFeedBack
OLESetData OLEStartDrag ProgrammaticChange
RangeHigh RangeLow RightClick
UIEnable Valid When

Métodos

AddItem AddListItem AddProperty
Clear CloneObject Drag
IndexToItemID ItemIDToIndex Move
OLEDrag ReadExpression ReadMethod
Refresh RemoveItem RemoveListItem
Requery ResetToDefault SaveAsClass
SetFocus WriteExpression WriteMethod
ZOrder    

Ejemplo

El ejemplo siguiente crea un control ListBox. El origen de los elementos que aparecen en el cuadro de lista es una matriz especificada con las propiedades RowSourceType y RowSource.

La propiedad MultiSelect para el cuadro de lista está definida como (.T.), lo que permite realizar múltiples selecciones en la lista. Los elementos que elija se mostrarán mediante las propiedades ListCount, Selected y List (que determinan el número de elementos de la lista y los elementos elegidos).

CLEAR

DIMENSION gaMyListArray(10)
FOR gnCount = 1 to 10  && Fill the array with letters
   STORE REPLICATE(CHR(gnCount+64),6) TO gaMyListArray(gnCount)
NEXT   

frmMyForm = CREATEOBJECT('Form')  && Create a Form
frmMyForm.Closable = .f.  && Disable the Control menu box

frmMyForm.Move(150,10)  && Move the form

frmMyForm.AddObject('cmbCommand1','cmdMyCmdBtn')  && Add "Quit" Command button
frmMyForm.AddObject('lstListBox1','lstMyListBox')  && Add ListBox control

frmMyForm.lstListBox1.RowSourceType = 5  && Specifies an array
frmMyForm.lstListBox1.RowSource = 'gaMyListArray' && Array containing listbox items

frmMyForm.cmbCommand1.Visible =.T.  && "Quit" Command button visible
frmMyForm.lstListBox1.Visible =.T.  && "List Box visible

frmMyForm.SHOW  && Display the form
READ EVENTS  && Start event processing

DEFINE CLASS cmdMyCmdBtn AS CommandButton  && Create Command button
   Caption = '\<Quit'  && Caption on the Command button
   Cancel = .T.  && Default Cancel Command button (Esc)
   Left = 125  && Command button column
   Top = 210  && Command button row
   Height = 25  && Command button height

   PROCEDURE Click
      CLEAR EVENTS  && Stop event processing, close Form
      CLEAR  && Clear main Visual FoxPro window
ENDDEFINE

DEFINE CLASS lstMyListBox AS ListBox  && Create ListBox control
   Left = 10  && List Box column
   Top = 10  && List Box row
   MultiSelect = .T.  && Allow selecting more than 1 item

PROCEDURE Click
   ACTIVATE SCREEN
   CLEAR
   ? "Selected items:"
   ? "---------------"
   FOR nCnt = 1 TO ThisForm.lstListBox1.ListCount
      IF ThisForm.lstListBox1.Selected(nCnt)  && Is item selected?
         ? SPACE(5) + ThisForm.lstListBox1.List(nCnt) && Show item
      ENDIF
   ENDFOR

ENDDEFINE

Vea también

ListBox (Control) | ListCount (Propiedad) | Diseñador de formularios | Usar controles