Ticket #1176 (new discussion)

Opened 3 years ago

Last modified 3 years ago

dropdownlist with key in grid

Reported by: aecker Assigned to: somebody
Priority: minor Milestone: 0.8.3
Component: ui Version: 0.8.4
Keywords: keyed dropdownlist grid Cc:

Description

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?

Change History

(follow-up: ↓ 2 ) 11/19/08 07:07:50 changed by ed

The grid editors are basic wx editor controls, and not fully-wrapped Dabo controls. You might try subclassing the GridListEditor? class in dGrid.py to behave as you like, and then set your new class as that column's 'listEditorClass' attribute.

I know that some work was done on the GridListEditor? class, but is no longer the default, due to problems with controlling its behavior. If this proves to be difficult to implement, you might want to create a virtual field with the displayed text, and then automatically update the actual ID field based upon the selection.

(in reply to: ↑ 1 ) 11/23/08 05:58:08 changed by aecker

Replying to ed:

Thanks for the hint with the GridListEditor? class and the virtual field. I will try to make this working and come back to this ticket on success/fail.

12/09/08 06:30:17 changed by aecker

I am stuck: I subclassed GridListEditor? as recommended and assigned it to the listEditorClass property of the grid column, but the Create() method of the list editor class methods not get called. I also tried to use makeGridEditor(). Any Ideas what I do wrong?