>I'm interested in building a ComboBox picklist that has a '< New >' selection in it (like Quicken's Pulldown picklists).
>I don't like the idea of using a view as the RowSource, because of the constant Requery()s, so I'm thinking of using the base table and (1) appending a blank record (with '< New >' as the name), (2) deleting it (and re-appending it if a pack is done), (3) always using buffering for the forms that use it, and (4) Recalling it in GotFocus() and Deleting it again in LostFocus().
>
>What kind of problems do you think I'll run into?
>
>TIA
I approached the problem from a different angle. My 'autoadd' combo has a custom property called iControlSource that I use instead of the native controlsource, and one called initialvalue that stores the value of the control on gotfocus. In the control's refresh event:
this.value = EVAL(this.iControlSource)
this.displayvalue = this.value
and in the lostfocus event:
IF type('this.icontrolsource') = "C"
REPLACE (this.icontrolsource) WITH THIS.DISPLAYVALUE
ENDIF
IF !(alltrim(THIS.DISPLAYVALUE) == alltrim(THIS.initialvalue)) and !empty(this.displayvalue)
itemfound = .F.
FOR i = 1 TO THIS.LISTCOUNT
IF alltrim(THIS.DISPLAYVALUE) = alltrim(THIS.LISTITEM(i))
itemfound = .T.
EXIT
ENDIF
ENDFOR
IF !itemfound
answer = MESSAGEBOX('The value you typed in is not in the list. Would you like to add it?', 32+4,"Add to List")
IF answer = 6
cInserttableName = left(this.rowsource, at(".", this.rowsource)-1)
cFieldname = right(alltrim(this.rowsource), len(this.rowsource) - at(".", this.rowsource))
INSERT INTO (cInsertTableName) ((cfieldname)) Values (this.displayvalue)
IF CURSORGETPROP('Buffering',(cinserttablename))>1
TABLEUPDATE(.T.,.T.,(cinserttablename))
ENDIF
ENDIF
ENDIF
ENDIF
This code checks to see if the value that the user typed (or chose for that matter) already exists in the list. If it does, cool, just replace the iControlSource field with the value (effectively making the list bound), if it does not, the user is asked whether or not he wants to add the new value to the list.
The reason for the iControlsource instead of just using controlsource, is that if you use the controlsource and the table contains a value that is not in the list, nothing is displayed. This control allows for the exception to the rule, when the user wants something that is not in the list, but doesn't necessarily want to make it a choice.
As a further hint, I also have a generic modal form that is used for lookuptable maintenance. For combos and listboxes whose rowsources are aliases I have a property called AllowRowsourceEdit. In the rightclick event of the box, I check this property and also check to see if the user has clearance to edit the table, and if they do, call the generic form, passing the alias specified in the rowsource. After control is returned to the listbox, I requery and the changes made in the maintenance form are reflected.
I realize that this is a pretty far stretch from the functionality that you had in mind, but I just wanted to help you brainstorm a little.
Erik Moore
Clientelligence