Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Appearance of checkbox in a grid
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00640051
Message ID:
00640124
Views:
23
What I did was created a Control subclass. This Control class is a container object roughly the height of a grid row and a width of about 70. I then dropped the check box into this container. Now I am able to set the left property of the check box so it appears centered in the grid column. I also added some properties to the control so it "inherits" the ControlSource, ReadOnly, etc., properties of the column the control is dropped in. I also added some resize code so the control is resized to the height and width of the column and reposition the checkbox so it is centered in the column.

Here is the source code I clipped from the View Source Code of the class browser:
**************************************************
*-- Class:        gridcheckbox (d:\vfp5apps\gis\classes\baseclass.vcx)
*-- ParentClass:  control
*-- BaseClass:    control
*-- Time Stamp:   03/01/01 11:04:07 AM
*
DEFINE CLASS gridcheckbox AS control


   Width = 40
   Height = 18
   BackStyle = 0
   BorderWidth = 0
   Name = "gridcheckbox"

   *-- Specifies if the user can edit a control, or 
   *-- specifies if a table or view associated with
   *-- a Cursor object allows updates.
   readonly = .F.

   *-- Contains the current value of the checkbox
   value = .F.


   ADD OBJECT chkbox AS checkbox WITH ;
      Top = 1, ;
      Left = 1, ;
      Height = 16, ;
      Width = 16, ;
      Caption = "", ;
      Name = "chkBox"


   PROCEDURE enabled_assign
      LPARAMETERS vNewVal
      THIS.Enabled = m.vNewVal
      THIS.chkBox.Refresh()
   ENDPROC


   PROCEDURE readonly_assign
      LPARAMETERS vNewVal
      THIS.readonly = m.vNewVal
      THIS.chkBox.Refresh()
   ENDPROC


   *-- Sets the ControlSource of the checkbox
   PROCEDURE setcontrolsource
      if not empty(This.Parent.ControlSource)
         This.chkBox.ControlSource =  This.Parent.ControlSource
      endif
   ENDPROC


   PROCEDURE Init
      with This
         .Resize()
         .SetControlSource()
         .chkBox.Refresh()
      endwith
   ENDPROC


   PROCEDURE Resize
      if upper(This.Parent.Parent.BaseClass) = "GRID"
         with This
            .Width  = .Parent.Width
            .Height = .Parent.Parent.RowHeight
            .chkBox.Left = max(0, int((.Width  - .chkBox.Width)  / 2))
            .chkBox.Top  = max(0, int((.Height - .chkBox.Height) / 2))
         endwith
      endif
   ENDPROC


   PROCEDURE Refresh
      This.chkBox.Refresh()
   ENDPROC


   *-- Called by the InteractiveChange of 
   *-- the CheckBox of this Control
   PROCEDURE intactchange
   ENDPROC


   PROCEDURE chkbox.Click
      DoDefault()
      This.Parent.Value = This.Value
      This.Parent.Click()
   ENDPROC


   PROCEDURE chkbox.Refresh
      if upper(This.Parent.Parent.Parent.BaseClass) <> "GRID"
         return
      endif
      This.Enabled = This.Parent.Parent.Enabled
      This.ReadOnly = This.Parent.Parent.ReadOnly
      *
      * Next commands are designed to over-ride the column settings
      *
      This.Enabled  = This.Parent.Enabled
      This.ReadOnly = This.Parent.ReadOnly
   ENDPROC


   PROCEDURE chkbox.KeyPress
      LPARAMETERS nKeyCode, nShiftAltCtrl
      local llEnabled
      llEnabled = .t.
      if !This.Enabled
         llEnabled = .f.
      endif
      if This.ReadOnly
         llEnabled = .f.
      endif
      do case
         case nKeyCode = 5  && up arrow
            skip -1
            if !bof()
               This.Parent.SetFocus()
            else
               locate
            endif
            nodefault
         case nKeyCode = 24  && down arrow
            skip
            if !eof()
               This.Parent.SetFocus()
            else
               skip -1
            endif
            nodefault
         case inlist(nKeyCode, 13, 32) and llEnabled
            *!* Enter or Spacebar pressed
            This.Click()
         otherwise
            if type("nShiftAltCtrl") <> "N" or isnull(nShiftAltCtrl)
               nShiftAltCtrl = 0
            endif
            DoDefault(nKeyCode, nShiftAltCtrl)
      endcase
      This.Parent.Parent.Parent.GridRowChange()
   ENDPROC


   PROCEDURE chkbox.InteractiveChange
      DoDefault()
      This.Parent.IntActChange()
   ENDPROC


ENDDEFINE
*
*-- EndDefine: gridcheckbox
**************************************************
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform