Subject Re: Derive grid's fieldName
From Tom <IHaveNoEmail@ddress>
Date Mon, 25 Oct 2021 13:59:38 -0400
Newsgroups dbase.getting-started

Hi Andy,

Hope you  slept well knowing you had the answer to my question. Akshat,
I got exactly as far as you did and got stuck. Don't feel bad.

The following code lets me retrieve information on a child form in a two
column array of field names on the left and their corresponding grid
header values on the right from any grid on any parent form. I hope that
  will let me build a query of the parent table grid from the child form.
I often use grid header text different from table field names. Stand by
for more questions and mind the wrap.

// attempt to derive this information  from form.oParent.GRID1 instead
of hand writing ...

                if type("form.oParent") = 'O'
                        form.aCFN_CHT = new array( form.oParent.GRID1.columnCount,2 )
                        *** 'ColumnFieldName_ColumnHeaderText == aCFN_CHT ***
                        local n
                        for n = 1 to form.oParent.GRID1.columnCount
                                form.aCFN_CHT[n,1] =
TRIM(form.oParent.GRID1.columns["COLUMN"+n].datalink.fieldname)
                                form.aCFN_CHT[n,2] =
TRIM(form.oParent.GRID1.columns["COLUMN"+n].headingControl.value)
                        endfor
                else
                        msgbox("No parent form. defined ...","Unable To Create List",48)
                endif
                *


My thanks to Akshat, Ken, Mervyn and especially Andy for the help they
all provided.

Regards,

Tom

On 10/24/21 7:59 PM, Andy Taylor wrote:
> Tom,
>
> Akshat almost had it with form.grdList.columns["Column1"].datalink but that, as he points out, is seen by dBASE an object reference
> rather than a string.  I investigated and found that it actually points to the fields object in the rowset, so the following is what you need:
>
> ? form.grdList.columns["Column1"].datalink.fieldname
>
> Your next task will be how to find the column number when the user clicks on a particular cell in the grid...
> It's late in the UK so I'm off to bed. :-)
>
> Andy
>
>> 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
>>
>> Thanks,
>> Tom
>