On Wednesday 07 July 2010 01:50:06 am Mike Turchenkov wrote:
> Hello, thanks a lot for dabo!
>
> Say please should I use a separate bizobj for populating list(and also
> combo and dropdown)box with key-name pairs that are calculated from another
> table?
In general yes.  I normally create a bizobj for my lists.  There are other 
ways  - for example if you need to use the same table twice.  But from what 
I'm reading the other methods will not be needed.  Just remember that you 
will need a way to retrieve a dataset to populate the list.
>
> As for now, getNamesAndKeys(self) is in Test_TableBizobj.py, DataSource is
> test_table for form and listbox simultaneousely. And when ValueMode = key,
> then I get
>
> File
> "/usr/local/lib64/python2.5/site-packages/Dabo-0.9.2-py2.5.egg/dabo/ui/uiwx
>/dControlItemMixin.py", line 239, in _setKeyValue
>     raise ValueError(_("Trying to set %s.Value to these invalid selections:
> %s") % (self.Name, invalidSelections))
> ValueError: Trying to set dComboBox.Value to these invalid selections: [3]

This error is common.  What it most like means is you have not accounted for 
the default key/string value of the list which is required.  I use something 
like the below code to populate a list.

def yourChoices(self):
       # I requery my bizobj normally a small table
        self.bizobj.requery()

       # get the data 
       yourDS = self.bizobj.getDataSet()

        #here I insure the default values of None and 0 are in the list
        availableChoices=['<None>']
        keyChoices=[0]

        # now I populate the rest of the list
        for row in yourDS:
            availableChoices.append(row['name_1'])
            keyChoices.append(row['pkid'])

        return availableChoices,keyChoices

You can use the above code to directly populate the list control.

Or you can add a class which is a little more advanced: 

class YourDropDown(dabo.ui.dDropdownList):
    def update(self):
        self.removeAll()
       #note I'm calling the above form method next
        self.Choices,self.Keys = self.Form.yourChoices()
        self.super()

Below is my UI code to call my class instance:
mylist=YourDropDown(self, Width = 500, ValueMode = 'key', RegID = 'yourID', 
DataSource = "tableName", DataField = "fieldName")

Now bind an event if needed:
mylist.bindEvent(dabo.dEvents.Hit, self._setFeeTime)

I have found that my forms open faster if I create an instance of a class on 
Linux.  

Johnf




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to