Choice

You can specify a SQL SELECT statement in the choices attribute.
+select companyname from customers
Put a + at the start of the statement will add a blank entry to the list.

Q:
The choiceList (‘Choices’) attribute for fields and grid columns can now be specified as a macro expression “{myproc(‘arg’,…}” that will be expanded in desktop, web and mobile.
It looks to me like the choices field is picking up the value as a literal (unless I am doing it wrong) and not running the macro.
I’ll wait for Yvonne or Barry to chime in.You can always use a custom control though.
For example, here is a custom control that conditionally lists the drop down choices based on employeeid.
customchoice1.jpg
The code is here –
I just create a container, add a readonly textbox and a combobox.
You can see the conditional logic in the proc.

proc customChoices(empid)

mycontainer = createObject("container")
mycontainer.layout = 1
mycontainer.autosize = 1
mycontainer.backcolor = "blue"
mycontainer.addobject("mytext","textbox")
mycontainer.addobject("cellcombo","combobox")
mytext.value = extension
mytext.readonly=.t.
if empid 
cellcombo.additems("one,two,three")
else
cellcombo.additems("Four,Five,Six")
endif

return mycontainer 
endproc
Also in my app, if I put some function in the “choice” delegate, Lianja return the name of the function..
A:
This is what you will see if you have an error in your dynamicchoice proc/func.
I am guessing you were making the same mistake I made with the choice list.
It has to return a comma seperated list.Looking at the example Yvonne pointed to, the documentation is using the sqlvalues built in function to create a list based on the query.This is now working for me.

proc dynamicchoice()

sqlvalues("select postalcode from employees")
myvals = astring(_sqlvalues)
return myvals
endproc

As with any custom section, you create your controls in classes, then use them.

In this example, I first subclass combobox as fabiocombo and add the valid event as a proc.

define class fabiocombo as combobox

proc valid()
Lianja.showMessage("Valid was fired")
endproc

enddefine

proc customChoices(empid)

mycontainer = createObject("container")
mycontainer.layout = 1
mycontainer.autosize = 1
mycontainer.backcolor = "blue"
mycontainer.addobject("mytext","textbox")
mycontainer.addobject("cellcombo","fabiocombo")
mytext.value = extension
mytext.readonly=.t.
if empid 
Advertisements

Choice

Q: combo box appear in a grid cell. After double clicking the column header, I have set the choices attribute to {1,2,3,4}.

A: remove the {}

 


Dynamic choice lists are choice lists based on data from a table, from a SQL SELECT, so they are dependent on the current data. Static choice lists are comma-separated hard-coded lists like ‘apples,pears,bananas’.


Q:
In the Data Dictionary for a field I entered Choices as: M,D,Q
But this doesn’t seem to be used anywhere?
Choices does work when entered for a grid column attribute or a field attribute.
How can I get the Data Dictionary Choices to be used everywhere instead?
A:
It will be picked up in Form Sections if you check the Inherit dictionary rules under Other Options in the Section Attributes. Fields also have an Inherit dictionary rules Attribute, which is checked True by default.
This functionality is not currently available in Grid Sections.
The default settings were debated, it was decided this way (fields Inherit true by default, overridden by the section Inherit false by default) because if you are using the dictionary, you just need to check 1 attribute for the section, but if you are not using the dictionary and have just changed some captions or added some tooltips your changes are not overwritten by dictionary values.
Can Inherit be set using code?
You can’t currently do it programmatically. Why not create a Template of a Form Section with the flag set and use that as your default Form Section?


Choicelists had an enhancement added to them so that if the SQL SELECT started with a + then a blank entry was added as the first entry in the list.
+SELECT omschrijving FROM titel ORDER BY omschrijving