Re: [dabo-users] Setting DropdownList.Value exception

Author: Paul McNett

Posted: 2009-07-27 at 09:05:31

Miguel Lopes wrote:

> This case maybe special because the form is loaded from a cdxml file.

> Note that properties are not being set in the class designer (as per

> my email above).

>

> In this case dropdownList properties are being set in the afterInitAll

> cdxml form method. The code is:

>

> def afterInitAll(self):

> _valueListProvider = self.Application.getAppInfo('valueListProvider')

> vlKeys, vlChoices = _valueListProvider.getKeysAndChoices('contact_title')

> dropDown = self.getObjectByRegID("dlTitle")

> dropDown.DataSource="contact"

> dropDown.DataField="title_id"

> dropDown.Keys = vlKeys

> dropDown.Choices = vlChoices

> dropDown.ValueMode="Key" # if both commented runs ok - but not

> in 'key' valueMode

> dropDown.Value = vlKeys[0] # if both commented runs ok - but

> not in 'key' valueMode

What happens with:

def afterInitAll(self):

...

dropDown.Keys = vlKeys

dropDown.Choices = vlChoices

dropDown.ValueMode = "key"

print self.getBizobj("contact")

dropDown.DataSource = "contact"

dropDown.DataField = "title_id"

print "choices", dropDown.Choices

print "keys", dropDown.Keys

After typing the above I just re-read your original post, and see that

the offending line is where you set dropDown.Value = vlKeys[0]. You

generally don't want to do that, because the Value is coming from the

bizobj and you are setting it to an arbitrary value which would get

saved to the bizobj.

However, you should be able to do that if you really want to, if the key

is present in the choices. Otherwise, you'll get the error you

originally reported. So, please still run with the above changes and

let's see what the choices and keys are.

Paul

©2009 Paul McNett