Subject Re: Derive grid's fieldName
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Sun, 24 Oct 2021 22:09:44 +0530
Newsgroups dbase.getting-started
Attachment(s) test_grid2.wfmtest_grid.wfm

Good Evening Tom,

> dBase 2019
> Windows 10
>
> Hi all,
>
> I am trying to derive the table field name that my grid column is
> attached to via program. That would be the word 'testdate' in the
> following example.The method escapes me at the moment. Your help would
> be appreciated.
>
>       columns["Column1"] = new GRIDCOLUMN(form.GRID1)
>        with (columns["Column1"])
>           dataLink = form.qdata.rowset.fields["testdate"]
>           editorType = 1    // EntryField
>           width = 90.0
>        endwith

I did try this out.
But failed.
2 forms are attached.
In test_grid.wfm columns are not defined. Just grid is datalinked to a
rowset.

I get error in ?form.grid1.columns["Column1"].datalink
The error is "Variable undefined"

I then made changes and the form is test_grid2
(Not much changed please review the code once)
?form.grid1.columns["Column1"].datalink
is just displaying "object"

Till it displays form.customers1.rowset.fields["customerid"] I am unable
to extract any other info.

I even tried ?form.grid1.columns["Column1"].datalink.value ,
?&form.grid1.columns["Column1"].datalink

But was unable to make any progress.
I am using plus 12 on windows 10

Regards
Akshat


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

class test_grid2Form of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 24.4545
      left = 4.7143
      top = 0.0
      width = 146.7143
      text = ""
   endwith

   this.DBASESAMPLES1 = new DATABASE(this)
   with (this.DBASESAMPLES1)
      left = 66.0
      top = 3.0
      width = 11.0
      height = 1.0
      databaseName = "DBASESAMPLES"
      active = true
   endwith

   this.CUSTOMERS1 = new QUERY(this)
   with (this.CUSTOMERS1)
      left = 52.0
      top = 2.0
      width = 9.0
      height = 1.0
      database = form.dbasesamples1
      sql = "select * from CUSTOMERS.DBF where customerid<35"
      active = true
   endwith

   this.GRID1 = new GRID(this)
   with (this.GRID1)
      dataLink = form.customers1.rowset
      columns["COLUMN1"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN1"])
         dataLink = form.customers1.rowset.fields["customerid"]
         editorType = 1        // EntryField
         width = 15.7143
      endwith
      columns["COLUMN2"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN2"])
         dataLink = form.customers1.rowset.fields["company"]
         editorType = 1        // EntryField
         width = 57.1429
      endwith
      columns["COLUMN3"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN3"])
         dataLink = form.customers1.rowset.fields["lastname"]
         editorType = 1        // EntryField
         width = 21.4286
      endwith
      columns["COLUMN4"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN4"])
         dataLink = form.customers1.rowset.fields["firstname"]
         editorType = 1        // EntryField
         width = 21.4286
      endwith
      columns["COLUMN5"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN5"])
         dataLink = form.customers1.rowset.fields["phone"]
         editorType = 1        // EntryField
         width = 28.5714
      endwith
      columns["COLUMN6"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN6"])
         dataLink = form.customers1.rowset.fields["address1"]
         editorType = 1        // EntryField
         width = 42.8571
      endwith
      columns["COLUMN7"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN7"])
         dataLink = form.customers1.rowset.fields["address2"]
         editorType = 1        // EntryField
         width = 42.8571
      endwith
      columns["COLUMN8"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN8"])
         dataLink = form.customers1.rowset.fields["city"]
         editorType = 1        // EntryField
         width = 28.5714
      endwith
      columns["COLUMN9"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN9"])
         dataLink = form.customers1.rowset.fields["state"]
         editorType = 1        // EntryField
         width = 7.1429
      endwith
      columns["COLUMN10"] = new GRIDCOLUMN(form.GRID1)
      with (columns["COLUMN10"])
         dataLink = form.customers1.rowset.fields["zip"]
         editorType = 1        // EntryField
         width = 14.2857
      endwith
      with (columns["COLUMN1"].headingControl)
         value = "CustomerID"
      endwith

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

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

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

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

      with (columns["COLUMN6"].headingControl)
         value = "Address1"
      endwith

      with (columns["COLUMN7"].headingControl)
         value = "Address2"
      endwith

      with (columns["COLUMN8"].headingControl)
         value = "City"
      endwith

      with (columns["COLUMN9"].headingControl)
         value = "State"
      endwith

      with (columns["COLUMN10"].headingControl)
         value = "Zip"
      endwith

      height = 7.5
      left = 10.0
      top = 5.5
      width = 133.0
   endwith

   this.rowset = this.customers1.rowset

   function form_onOpen()
      ?form.grid1.columncount
                ?form.grid1.columns["Column1"].datalink
                inspect(form)
      return

endclass



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

class test_gridForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 24.4545
      left = 4.7143
      top = 0.0
      width = 146.7143
      text = ""
   endwith

   this.DBASESAMPLES1 = new DATABASE(this)
   with (this.DBASESAMPLES1)
      left = 66.0
      top = 3.0
      width = 11.0
      height = 1.0
      databaseName = "DBASESAMPLES"
      active = true
   endwith

   this.CUSTOMERS1 = new QUERY(this)
   with (this.CUSTOMERS1)
      left = 52.0
      top = 2.0
      width = 9.0
      height = 1.0
      database = form.dbasesamples1
      sql = "select * from CUSTOMERS.DBF where customerid<35"
      active = true
   endwith

   this.GRID1 = new GRID(this)
   with (this.GRID1)
      dataLink = form.customers1.rowset
      height = 7.5
      left = 10.0
      top = 5.5
      width = 133.0
   endwith

   this.rowset = this.customers1.rowset

   function form_onOpen()
      ?form.grid1.columncount
                ?form.grid1.columns["Column1"].datalink
                inspect(form)
      return

endclass