Article ID: 157048
Article Last Modified on 6/29/2004
HOME(2)+ "tastrade\bitmaps\checkbx.bmp"
HOME(2)+ "tastrade\bitmaps\box.bmp"
Please modify the code examples below when running this code in Visual
FoxPro 6.0.
DIMENSION ThisForm.ItemSel(ThisForm.NumLstItm)
FOR i= 1 to ThisForm.NumLstItm
ThisForm.ItemSel(i)=0
endfor
MultiSelect = .F. - False
Name = List1
RowSourceType = 1 - Value
RowSource = One,Two,Three,Four,Five
NOTE: Make sure that the NumLstItm property of the form is set to the
same number as the number of items you have in the RowSource property of
the ListBox control. For example, if the NumLstItm property of the form
is set to 5, then the RowSource property of the ListBox control should
contain 5 items separated by commas.
This.Picture=HOME()+"samples\tastrade\bitmaps\box.bmp"
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF LASTKEY()!= 5 AND LASTKEY() != 24
IF ThisForm.ItemSel(This.ListItemID)=0
This.Picture(This.ListItemID)=HOME()+ ;
"samples\tastrade\bitmaps\checkbx.bmp"
ThisForm.ItemSel(This.ListItemID)=1
ELSE
IF ThisForm.ItemSel(This.ListItemID)=1
This.Picture(This.ListItemID)=HOME()+"samples\tastrade\bitmaps\box.bmp"
ThisForm.ItemSel(This.ListItemID)=0
ENDIF
ENDIF
ENDIF
When you run the form, the Icons of all the Items in the ListBox display an
empty check box. With the above code, if you left-click an item, then the
icon of the item changes to a Box with an "x" in it.
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode=32
IF ThisForm.ItemSel(This.ListItemID)=0
This.Picture(This.ListItemID)=HOME()+ ;
"samples\tastrade\bitmaps\checkbx.bmp"
ThisForm.ItemSel(This.ListItemID)=1
ELSE
IF ThisForm.ItemSel(This.ListItemID)=1
This.Picture(This.ListItemID)=HOME()+"samples\tastrade\bitmaps\box.bmp"
ThisForm.ItemSel(This.ListItemID)=0
ENDIF
ENDIF
ENDIF
With the above code if you press the space bar, the Icon of the highlighted
Item toggles between an empty check box and a check box with an "x" in it.
isel=""
FOR i = 1 TO ThisForm.NumLstItm
IF ThisForm.ItemSel(i)=1
if i = 1
isel = isel + ThisForm.List1.ListItem(i)
ELSE
isel = isel + "; " + ThisForm.List1.ListItem(i)
endif
ENDIF
ENDFOR
WAIT WINDOW isel
Keywords: kbhowto KB157048