Subject Re: grid focus
From Mervyn Bick <invalid@invalid.invalid>
Date Fri, 30 Dec 2022 09:24:00 +0200
Newsgroups dbase.getting-started
Attachment(s) ghor_a.wfm

On 2022/12/28 21:30, Mustansir Ghor wrote:
> Dear All
>
> I have a rowset datalinked to grid.
>
> The grid behaves different with keyboard uparrow or downarrow and mouse click. The difference is observed in the behavoiur of onnavigate method. Keyboard arrows does respond but onclick event does not.
>
> Can anybody advise how to simulate onclick event to also respond.
>
> Best Regards
> Mustansir

I have no idea why the behaviour is different when using the keyboard
and using the mouse but a simple fix is to use each grid's onLeftMouseUp
event handler to force focus to the ESCAN entryfield.

    function GRID1_onLeftMouseUp(flags, col, row)
       if form.escan.visible = true
          form.escan.setfocus()
       endif
       return

To indicate if a grid has focus you can use the grid's onGotFocus and
onLostFocus to change the borderstyle property or, perhaps, the
background property.

    function GRID1_onGotFocus()
       this.borderstyle := 5
       return

    function GRID1_onLostFocus()
       this.borderstyle := 0
       return

I use a different date format (YMD) so your form opened with empty
grids.  I've added code to the form's onOpen event handler so that the
form will run no matter what the date format is set to.

You have used a CASE construct in the ESCAN entryfield's onLostFocus
event handler.  Bear in mind that in a CASE construct dBASE stops
testing as soon as the first test returns true.  You have no code after
the test for case empty(this.value) which means, unless this is actually
what you want, the user can simply move focus elsewhere leaving the
value unverified.

do case                
    case empty(this.value)
    //no code here
   case not
form.qsales.rowset.fields["CODE"].lookuprowset.fields["code"].value==this.value
    and ;
    empty(form.qsales.rowset.fields["VERIFY"].value)        
    msgbox("Scan Code Unmatched","",48)
.....
endcase

A revised version of your form is attached.

Mervyn.






** END HEADER -- do not remove this line
//
// Generated on 2022-12-30
//
parameter bModal
local f
f = new ghor_aForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class ghor_aForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 29.0
      left = -75.8571
      top = 0.9545
      width = 190.2857
      text = ""
   endwith

   this.QSALES = new QUERY(this)
   with (this.QSALES)
      left = 15.0
      top = 1.0
      sql = "select * from sales where sno=:msno"
      params["msno"] = ""
      active = true
   endwith

   with (this.QSALES.rowset)
      onNavigate = class::ROWSET_ONNAVIGATE
   endwith

   this.QTEMPSAL = new QUERY(this)
   with (this.QTEMPSAL)
      left = 21.0
      sql = "select distinct sno,sdate,op from sales where sdate between :mdate1 and :mdate2"
      params["mdate1"] = {2019-10-14}
      params["mdate2"] = {2019-10-14}
      active = true
   endwith

   with (this.QTEMPSAL.rowset)
      onNavigate = class::ROWSET_ONNAVIGATE1
   endwith

   this.LINE3 = new LINE(this)
   with (this.LINE3)
      left = 68.0
      right = 68.0
      top = 3.0
      bottom = 22.0
      width = 1
   endwith

   this.PBCLOSE = new PUSHBUTTON(this)
   with (this.PBCLOSE)
      onClick = class::PBCLOSE_ONCLICK
      height = 1.5
      left = 48.0
      top = 18.5
      width = 16.0
      text = "Close The Form"
   endwith

   this.GRID2 = new GRID(this)
   with (this.GRID2)
      onGotFocus = class::GRID2_ONGOTFOCUS
      onLostFocus = class::GRID2_ONLOSTFOCUS
      onLeftMouseUp = class::GRID2_ONLEFTMOUSEUP
      dataLink = form.qtempsal.rowset
      columns["COLUMN1"] = new GRIDCOLUMN(form.GRID2)
      with (columns["COLUMN1"])
         dataLink = form.qtempsal.rowset.fields["sno"]
         editorType = 1        // EntryField
         width = 8.5714
      endwith
      columns["COLUMN2"] = new GRIDCOLUMN(form.GRID2)
      with (columns["COLUMN2"])
         dataLink = form.qtempsal.rowset.fields["sdate"]
         editorType = 1        // EntryField
         width = 12.0
      endwith
      columns["COLUMN4"] = new GRIDCOLUMN(form.GRID2)
      with (columns["COLUMN4"])
         dataLink = form.qtempsal.rowset.fields["op"]
         editorType = 1        // EntryField
         width = 11.4286
      endwith
      with (columns["COLUMN1"].headingControl)
         value = "SNO"
      endwith

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

      with (columns["COLUMN4"].headingControl)
         value = "OPERATO"
      endwith

      allowEditing = false
      allowAddRows = false
      height = 13.5
      left = 24.0
      top = 3.5
      width = 40.0
   endwith

   this.GRID1 = new GRID(this)
   with (this.GRID1)
      onGotFocus = class::GRID1_ONGOTFOCUS
      onLostFocus = class::GRID1_ONLOSTFOCUS
      onLeftMouseUp = class::GRID1_ONLEFTMOUSEUP
      fontSize = 13.0
      dataLink = form.qsales.rowset
      columns["COLUMN1"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN1"])
         dataLink = form.qsales.rowset.fields["code"]
         editorType = 1        // EntryField
         width = 22.0
      endwith
      columns["COLUMN2"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN2"])
         dataLink = form.qsales.rowset.fields["qty"]
         editorType = 1        // EntryField
         width = 10.5714
      endwith
      columns["COLUMN5"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN5"])
         dataLink = form.qsales.rowset.fields["verify"]
         editorType = 1        // EntryField
         width = 12.2857
      endwith
      with (columns["COLUMN1"].headingControl)
         value = "CODE"
      endwith

      with (columns["COLUMN2"].editorControl)
         picture = "999,999"
      endwith

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

      with (columns["COLUMN5"].headingControl)
         value = "VERIFIED BY"
      endwith

      allowEditing = false
      allowAddRows = false
      height = 17.5
      left = 69.0
      top = 3.0
      width = 53.0
   endwith

   this.ESCAN = new ENTRYFIELD(this)
   with (this.ESCAN)
      onLostFocus = class::ESCAN_ONLOSTFOCUS
      onChange = class::ESCAN_ONCHANGE
      visible = false
      height = 1.0
      left = 102.0
      top = 21.0
      width = 20.0
      value = ""
   endwith

   this.LBSCAN = new TEXTLABEL(this)
   with (this.LBSCAN)
      visible = false
      height = 1.0
      left = 71.0
      top = 21.0
      width = 31.0
      text = "For this item verification , Scan Here"
   endwith


        
  
        

   function GRID1_onGotFocus()
      this.borderstyle := 5
      return

   function GRID1_onLeftMouseUp(flags, col, row)
      if form.escan.visible = true
         form.escan.setfocus()
      endif  
      return

   function GRID1_onLostFocus()
      this.borderstyle := 0
      return

   function GRID2_onGotFocus()
      this.borderstyle := 5
      return

   function GRID2_onLeftMouseUp(flags, col, row)
      if form.escan.visible = true
         form.escan.setfocus()
      endif  
      return

   function GRID2_onLostFocus()
      this.borderstyle := 0
      return

   function PBCLOSE_onClick()
        
      close databases
                form.close()
        
      return


   function form_onOpen()
     with (this)
    
      height = 24.5909
      left = 1.7143
      top = 4.0
      width = 179
    
     endwith
            
      form.qtempsal.params['mdate1'] = new date(2022,11,28)
      form.qtempsal.params['mdate2'] = new date(2022,11,28)
      form.qtempsal.requery()      
//                form.qtempsal.active=true        
                if form.qtempsal.rowset.count()>0
                 form.qtempsal.rowset.first()
                 form.qsales.active=true
                endif
  
        
        
      return
                


      function ESCAN_onChange()
      
      this.keyboard("{Tab}")
                class::escan_onlostfocus()
                
      return

   function ESCAN_onLostFocus()
           do case
                
                case empty(this.value)
                
                
                case not form.qsales.rowset.fields["CODE"].lookuprowset.fields["code"].value==this.value and ;
                 empty(form.qsales.rowset.fields["VERIFY"].value)
                
       msgbox("Scan Code Unmatched","",48)
                 form.qsales.rowset.next()

            if form.qsales.rowset.endofset
                 form.lbscan.visible=false
                 form.escan.visible=false
                
                 form.grid2.setfocus()
                 endif
        
                
      case  form.qsales.rowset.fields["CODE"].lookuprowset.fields["code"].value==this.value
                 form.qsales.rowset.fields["VERIFY"].value=_app.session.user()
                 form.qsales.rowset.save()
                
            form.qsales.rowset.next()

            if form.qsales.rowset.endofset
                 form.lbscan.visible=false
                 form.escan.visible=false
                
                 form.grid2.setfocus()
                 endif
                
                endcase
      return


   function rowset_onNavigate(type, nRows)
          
      pref = this.parent.parent
                if this.endofset
                 pref.grid2.setfocus()
                 return
                endif
                
                pref.escan.value=""
                if empty(this.fields["verify"].value)
                 pref.lbscan.visible=true
                 pref.escan.visible=true
                 pref.escan.setfocus()
                else
                 pref.lbscan.visible=false
                 pref.escan.visible=false
                endif
                
      return

   function rowset_onNavigate1(type, nRows)
      this.parent.parent.qsales.params["msno"]=this.fields["sno"].value
           this.parent.parent.qsales.requery()
                this.parent.parent.qsales.rowset.first()
                oref = this.parent.parent
                do while not oref.qsales.rowset.endofset
                 if not empty(oref.qsales.rowset.fields["verify"].value)
                  oref.qsales.rowset.next()
                 else
                  exit
                 endif
                enddo
     return

endclass