5.00
WINDOWS
kbtool kbhowto
The information in this article applies to:
- Microsoft Visual FoxPro for Windows, version 5.0
SUMMARY
If you click Toolbars on the View menu, the Toolbars dialog box appears,
which allows you to manipulate check boxes from within a ListBox Control.
This article illustrates how you can create this functionality using Visual
FoxPro.
MORE INFORMATION
Use the following steps to create a ListBox control similar to the one in
the Visual FoxPro Toolbars dialog box:
- Create a form using the "CREATE FORM test" command. This example assumes
that you have installed Visual FoxPro and all its components to the
C:\Vfp directory, and this is what is returned by the VFP HOME()
command.
- Add two new properties, NumLstItm and ItemSel[1], to the form. The first
property holds the number of items you would like the ListBox control to
display, and the second property keeps track of whether specific items
in the ListBox control are selected(1) or not selected(0).
- Right-click the form and click Properties on the Shortcut menu. This
takes you to the Properties dialog box for the form.
- Select the NumLstItm property from the All tab or the Other tab of the
Property dialog box, and set it to the number of items you want to have
in the ListBox control--for example, set NumLstItm to 5.
- Add the following code to the INIT event of the form:
DIMENSION ThisForm.ItemSel(ThisForm.NumLstItm)
FOR i= 1 to ThisForm.NumLstItm
ThisForm.ItemSel(i)=0
endfor
- Add a ListBox control to the form with the following settings:
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.
- Add the following code to the INIT event of the ListBox control:
This.Picture=HOME()+"samples\tastrade\bitmaps\box.bmp"
- Add the following code to the Click event of the ListBox:
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.
- Add the following code to the KEYPRESS event of the ListBox:
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.
- Create a command button and set its caption to "List of Selected
Items." Add the following code to the click event of the button:
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
|