Subject Re: logical field check box behavior in a grid
From Mervyn Bick <invalid@invalid.invalid>
Date Sun, 25 Jun 2017 14:26:34 +0200
Newsgroups dbase.getting-started
Attachment(s) test_gridtick.wfm

On 2017-06-25 12:38 AM, Charlie wrote:
> I was wondering if there is a way to allow the user to click once on a checkbox in a grid and have checkbox = true without having to click twice??  As a matter of fact in all my grids I have to click twice then click on another field in order to have the checkbox act like it is true.
>
> I'd love to find a way to have the checkbox become truly true after only one click on the check box.  Is this possible????

It can be done but it comes at a price. :-(

Normally, the first left click sets focus to the tickbox and the second
click toggles the value.  If you have clicked the wrong record you can
simply click a third time to reverse the error.

The editorcontrol's onLeftMouseDown event handler can be used to change
a tickbox with one click. The problem arises if you have clicked the
wrong record and want to restore the original setting.  You need to move
focus away from the tickbox and then click on it again.  This means that
you need to click on a different column to move focus away.  If you
click on another tickbox it changes.  If it's not one due to be
changed.....

I've used the right mouse click to reverse an incorrectly changed
tickbox.  This works but may confuse the heck out of your users.

Mervyn.



if file('test_gridtick.dbf')
  // drop table test_gridtick
endif

if not file('test_gridtick.dbf')
   create table test_gridtick  (id autoinc,data character(15),tickbox boolean)

   use test_gridtick
   generate 5
   use
endif
** END HEADER -- do not remove this line
//
// Generated on 2017-06-25
//
parameter bModal
local f
f = new test_gridtickForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class test_gridtickForm of FORM
   with (this)
      height = 14.1818
      left = 8.7143
      top = 5.0455
      width = 74.1429
      text = ""
   endwith

   this.TEST_GRIDTICK1 = new QUERY(this)
   with (this.TEST_GRIDTICK1)
      left = 4.0
      width = 11.0
      height = 1.0
      sql = 'select * from "test_gridtick.DBF"'
      active = true
   endwith

   this.GRID1 = new GRID(this)
   with (this.GRID1)
      dataLink = form.test_gridtick1.rowset
      columns["COLUMN1"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN1"])
         dataLink = form.test_gridtick1.rowset.fields["id"]
         editorType = 1        // EntryField
         width = 15.7143
      endwith
      columns["COLUMN2"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN2"])
         dataLink = form.test_gridtick1.rowset.fields["data"]
         editorType = 1        // EntryField
         width = 21.4286
      endwith
      columns["COLUMN3"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN3"])
         dataLink = form.test_gridtick1.rowset.fields["tickbox"]
         editorType = 2        // CheckBox
         width = 10.0
      endwith
      with (columns["COLUMN1"].headingControl)
         value = "id"
      endwith

      with (columns["COLUMN2"].headingControl)
         value = "data"
      endwith

      with (columns["COLUMN3"].editorControl)
         onLeftMouseDown = class::EDITORCONTROL_ONLEFTMOUSEDOWN
         onRightMouseDown = class::EDITORCONTROL_ONRIGHTMOUSEDOWN
      endwith

      with (columns["COLUMN3"].headingControl)
         value = "tickbox"
      endwith

      height = 9.0
      left = 9.0
      top = 4.0
      width = 58.0
   endwith

   this.TEXT1 = new TEXT(this)
   with (this.TEXT1)
      height = 3.0
      left = 44.0
      top = 0.0
      width = 24.0
      text = "Left mouse click to change checkbox value. Right mouse click to reverse change."
   endwith

   this.rowset = this.test_gridtick1.rowset

   function editorControl_onLeftMouseDown(flags, col, row)
      this.value = not this.value
      return


   function editorControl_onRightMouseDown(flags, col, row)
       this.value = not this.value
      return

endclass