Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie question on ListBox
Message
From
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:
01393608
Views:
56
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform