Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie question on ListBox
Message
 
 
To
07/04/2009 10:18:33
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01393588
Message ID:
01393609
Views:
42
>I want to use a ListBox control for the following purpose:
>
>The listbox will have 2 column, the 1st column a check box. The 2nd column should be bound to a column of a cursor.
>>
>User then can check any number of rows of the list box as selected items.

>
>
>**************************************************
>*-- Class:        lstchkbox
>*-- ParentClass:  listbox
>Define Class lstchkbox As ListBox
>
>  Picture = "..\graphics\box.bmp"
>  ColumnCount = 1
>  ColumnLines = .F.
>  Name = "lstchkbox"
>  Dimension aselected[1]
>
>  *-- Checks and unchecks the box depending on whether or not the item is selected
>  Procedure setlistitem
>    With This
>      If .ListIndex > 0
>        If .aselected[.ListIndex]
>          .Picture[.ListIndex] = 'Box.bmp'
>          .aselected[.ListIndex] = .F.
>        Else
>          .Picture[.ListIndex] = 'CheckBx.bmp'
>          .aselected[.ListIndex] = .T.
>        Endif
>      Endif
>    Endwith
>  Endproc
>
>  *-- Resets the aSelected array so none of the items are selected
>  Procedure Reset
>    With This
>      *** clear all selections
>      *** If other behavior is required by default, put it here and call this
>      *** method from any place that the list box's contents must be reset
>      .ListIndex = 0
>      Dimension .aselected[.ListCount]
>      .aselected = .F.
>    Endwith
>  Endproc
>
>  *-- Keeps correct pictures for selections when the list box is refreshed
>  Procedure refreshlist
>    Local lnItem
>    With This
>      For lnItem = 1 To .ListCount
>        .Picture[ lnItem ] = Iif( .aselected[ lnItem ], 'CheckBx.bmp', 'Box.bmp' )
>      Endfor
>    Endwith
>  Endproc
>
>  Procedure GotFocus
>    ListBox::GotFocus()
>    This.refreshlist()
>    Nodefault
>  Endproc
>
>  Procedure KeyPress
>    Lparameters nKeyCode, nShiftAltCtrl
>    If nKeyCode = 32 Or nKeyCode = 13
>      This.setlistitem()
>    Endif
>  Endproc
>
>  Procedure Click
>    *** Clicking the mouse gives a lastkey() of 13
>    If Lastkey() = 13
>      This.setlistitem()
>    Endif
>  Endproc
>
>  Procedure Init
>    If DoDefault()
>      This.Reset()
>    Endif
>  Endproc
>Enddefine
>
Thank you very much for your code.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform