On Wednesday 19 November 2008 05:26:23 am Dabo Trac wrote:
> #1176: dropdownlist with key in grid
> -------------------------------------+-------------------------------------
>- Reporter: aecker | Owner: somebody
> Type: discussion | Status: new
> Priority: minor | Milestone: 0.8.3
> Component: ui | Version: 0.8.4
> Keywords: keyed dropdownlist grid |
> -------------------------------------+-------------------------------------
>- I don't could find out how to add key values to a dropdownlist (column
> object) within a grid column. I can use wxGridChoiceEditor to get a
> dropdownlist like in the following example:
>
> {{{
> self.addColumn(
> dabo.ui.dColumn(self, DataField="C_DESC",
> Caption="Company",
> Sortable=True, Searchable=True, Editable=True, DataType="list",
> ListEditorChoices =
> self.getChoices(self.Application.biz.Companies) ))
>
> def getChoices(self, bizClass):
> app = self.Application
> bizObj = bizClass(app.dbConnection)
> bizObj.requery()
> pref = bizObj.KeyField[:1]
> choices = ["(select)"]
> #keys = {"" : 0}
> for co in bizObj.bizIterator():
> choices.append("%s" % bizObj.getFieldVal(pref +
> "_DESC"))
> #keys[bizObj.getFieldVal(pref + "_ID")] =
> len(choices) - 1
> return choices
> }}}
>
> But the 'value' of this column is always the diplayed text/caption of the
> list items. I would need a key value instead like the in the dabo
> dDropdownList. Any ideas/hints?
I can answer the first part of your question by providing a simple example of
using a key in a dropdown. Not sure what Ed is attempting to tell you.
The method countryChoices returns the key and text (Choices) values to provide
a list of countries. I also append a '<None>' in my example because I wanted
to show a "<None>" when there was no data available.
Take note that I need "ValueMode = 'key' " and my datafield is a FK. The
method is simple and it expects that I have DataSet available.
choices,keys = self.Form.addrctryChoices()
countryctrl=dabo.ui.dDropdownList(self,ValueMode='key',RegID='addrctrychoicesID',
Choices=choices, Keys=keys,DataSource ="public.arcadr", DataField
= "fk_country")
countryctrl.bindEvent(dabo.dEvents.Hit,self.onaddrctrySelected)
def countryChoices(self):
self.countryChoices=[]
self.countryKeys=[]
for row in self.countryDS:
self.countryChoices.append(row['ccountry'].strip())
self.countryKeys.append(row['pkid'])
self.countryChoices.append('<None>')
self.countryKeys.append(0)
return self.countryChoices,self.countryKeys
--
John Fabiani
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]