Re: [dabo-users] Very Simple dropdownlist

Author: John

Posted: 2009-07-17 at 14:59:55

On Friday 17 July 2009 11:33:54 am Carey Gagnon wrote:

> Ok, I have now got the drop down populating properly with all error message

> gone. Everything is saving to the database properly as well.

> Here's the appropriate section of the cdxml file:

>

> <dDropdownList sizerInfo="{'RowSpan': 1, 'ColSpan': 1, 'HAlign': 'Left',

> 'ColExpand': True}" Keys="[u'0', u'1', u'2',

> u'3']" rowColPos="(5, 1)" Choices="[u'-Select-',

> u'AL', u'TX', u'WA']"

> designerClass="controlMix" DataSource="clients"

> DataField="stateprov"></dDropdownList>

>

>

> I added the following line to the bizobj file which stopped the

> "String must be present in the choices" error:

>

> self.DefaultValues = {"stateprov": "-Select-"}

>

> My Question now (looking at the cdxml snippet), is there anyway to display

> the full name of the state in the drop down list, but save the abbreviation

> to the database on self.Form.save()

>

> Thanks in advance

> Carey

Of course - this is Dabo after all.

In general listCtrl controls have two 'ValueMode" s. Using the 'key'

or 'string'. The default is to use string value in the choices list. But you

can change it to "ValueMode = key"

So now you need to set the key and choices to match each other.

In your form select the dropdown control. Copy your "Choices" ( I assume they

are similar to ['CA','WA','TX',...]) and put it into the 'Keys'. Now set the

choices similar to ['California', 'Washington', 'Texas', ....]. Just make

sure they match. Next set the 'ValueMode' from 'string' to 'key'.

Recall you will need to do something with the None value. I always use '0' as

my key for a None value.

Johnf

©2009 John