Page 1 of 1

Select an Item in a DropDownList

Posted: Thu Oct 06, 2016 12:50 pm
by soa
Basic question

I've loaded a dropdown list with items and and I want the first item to be selected initially so the user never sees a blank entry but I can't see how to do this.

Re: Select an Item in a DropDownList

Posted: Thu Oct 06, 2016 1:05 pm
by Stewart Marshall
You need to set the appropriate item to be the FocusItem (http://docs.lansa.com/14/en/lansa016/PR ... usItem.htm). As Dropdowns typically only allow a single item to be selected, the FocusItem will appear selected.

Best practice is to ensure that the appropriate field values are updated as well, so a Get_Entry is also required.

Code: Select all

#DropDown.Items<1>.Focus := True
Get_Entry Number(#DropDown.FocusItem.Entry) From_List(#DropDown)

Re: Select an Item in a DropDownList

Posted: Thu Oct 06, 2016 1:30 pm
by soa
Thanks for the quick response but this isn't working for me. I have

Clr_List Named(#ddCalyrStudyr)

For Each(#entry) In(#Model.Student.Entries)
Add_Entry To_List(#ddCalyrStudyr)
Endfor

#ddCalyrStudyr.items<1>.Focus := true
Get_Entry Number(#ddCalyrStudyr.FocusItem.Entry) From_List(#ddCalyrStudyr)

but the get_entry fails with an error of

Uncaught TypeError: Cannot read property 'getEntry' of null

If I comment out this line it does not crash but neither is anything selected.

Re: Select an Item in a DropDownList

Posted: Thu Oct 06, 2016 2:37 pm
by Stewart Marshall
For some reason it seems the FocusItem isn't accessible. I'll look in to this.

If the items aren't being sorted, you can use the specific entry number

Code: Select all

Get_Entry Number(1) From_List(#DropDown)

Re: Select an Item in a DropDownList

Posted: Thu Oct 06, 2016 3:02 pm
by soa
I've modified the code to

#ddCalyrStudyr.items<1>.Focus := true
Get_Entry Number(1) From_List(#ddCalyrStudyr)

but the dropdown is still displayed with a blank selection.

Also If I select an item from the list and then tab away to another control the value goes blank again. There is a property of the dropdown -'ShowSelection' - which seems to address this I have this checked and it makes no difference.

Re: Select an Item in a DropDownList

Posted: Thu Oct 06, 2016 3:42 pm
by GregSippel
Try the following

Code: Select all

Clr_List Named(#DropDown)

For Each(#entry) In(#CLIENTDATA.Balances)

Add_Entry To_List(#DropDown)

* Add Related Reference
#DropDown.CurrentItem.RelatedReference <= #entry

* Set Column Display Text
#DisplayColumn.CurrentItem.Value := #entry.DisplayName

Endfor

* since we have logged in as a specific sub-account, select it
#DropDown.Items<1>.Selected := True

Re: Select an Item in a DropDownList

Posted: Thu Oct 06, 2016 5:08 pm
by Stewart Marshall
When you expand the drop down, are there any values visible at all?

Unless you actually specify a value for each item, either by populating field values or setting the Value property of the currentitem for a particular column, there are no values in the dropdown to be selected. This would certainly explain why get blank selection every where.

Here's a simple example of how a drop down works. This uses a single column based on xDemoNumber.

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Height(712) Width(1024)
Define_Com Class(#PRIM_LIST.DropDown) Name(#DropDown1) ColumnHeaderHeight(0) ColumnLines(False) DisplayPosition(1) Left(192) Parent(#COM_OWNER) RowLines(False) ShowSelection(False) TabPosition(1) Top(16) Height(39) Width(201)
Define_Com Class(#PRIM_LIST.Number) Name(#ColumnXDEMONUMB1) ColumnUnits(Proportion) ColumnWidth(1) DisplayPosition(1) Increment(1) Parent(#DropDown1) Source(#xDemoNumber) Wrap(False)
Define_Com Class(#PRIM_PHBN) Name(#Button1) Caption('Another Control') DisplayPosition(2) Left(16) Parent(#COM_OWNER) TabPosition(2) Top(16) Width(158) Height(41)

Evtroutine Handling(#Com_owner.CreateInstance)

Begin_Loop Using(#xDemoNumber) To(10)

Add_Entry To_List(#DropDown1)

End_Loop

#DropDown1.Items<1>.Focus := true
Get_Entry Number(1) From_List(#DropDown1)

Endroutine

End_Com

Re: Select an Item in a DropDownList

Posted: Thu Oct 06, 2016 9:24 pm
by soa
The dropdown certainly has values. I have several fields in the list all hidden except one. When I click the list my items are visible and in the change event the correct hidden fields are exposed and the rest of the interface works accordingly. It works perfectly except that set selection in code doesn't work and the selected content disappears as soon as focus list lost.

I notice that Greg's example uses

#DropDown.Items<1>.Selected := True

rather than

#DropDown1.Items<1>.Focus := true

I'll try that tomorrow.

Re: Select an Item in a DropDownList -Solved

Posted: Fri Oct 07, 2016 10:23 am
by soa
Massive doh! here.

Turns out that the values where there all along but were made invisible by the themedrawstyle!.

My form has a dark theme (white against dark grey). I have a drawstyle called Plaintext which applies this and is set at panel level. All the label items inherit this value but with the dropdown I had to set it explicitly.

Thanks Greg & Stewart for your responses.