Recent

Author Topic: DBLookupComboBox Not in List  (Read 1676 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
DBLookupComboBox Not in List
« on: September 24, 2017, 09:04:52 pm »
HI,

Hope someone can help.

I'm trying to deal with a new entry added by the user to a LookupComboBox.
In MS Access we have a flag (LimitToList) and event (NotInList) to deal with this situation.
I know these don't exist, so what I thought I'd do was to get the value entered when the DoEditingDone event fires and see if it is in the underlying table, if not I was going to ask the user if they wanted to add it and if so to bring up a new form to get all the data needed and then add it to the table behind the LookupComboBox and manually store the value in the associated data field of the ComboBox.

However, when the DoEditingDone event fires, the value in .Text is empty, presumably because it has already detected that it is not in the dropdown list.

Can anyone throw any light on what I could try next?

Many thanks
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DBLookupComboBox Not in List
« Reply #1 on: September 24, 2017, 10:24:58 pm »
I'm doing the opposite. I have a add buttong next to a dblookup that the users can press to add new values and when finished the dblookupcombo re query its data and auto selects the new value,
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: DBLookupComboBox Not in List
« Reply #2 on: September 24, 2017, 10:53:14 pm »
I thought about that, but it didn't feel natural in the sense that the user would firstly go to the dropdown to look for the value and not find it, then have to go somewhere else, i.e. the button to add it, and then back and find what they had already tried to find (and it will be there this time).

What I've done so far is to capture OnChange and keep track of the entered value.
Then when the user exits the ComboBox it goes to OnExit.
Here I first check if the .Text field is non empty which means the ComboBox found the entry so I just exit.
If the saved value I'm collecting is blank then maybe the user wants to actually delete the entry so I ask and do what they want.
If the saved value is non-blank then I look it up in the ComboBox underlying query (I don't think I actually need to do this because if it was in the Query it wouldn't get this far). Anyway, if it doesn't find it I know that it must be a new entry so then I ask the user if they want to add new data for the dropdown value they entered.
If they say yes I bring up a new form and let them enter the new data (with the dropdown value they entered already completed).
When they accept (cancel just drops everything) I get the new ID of the new value just entered and put it in the field attached to the ComboBox.

Halfway through the code right now.

Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

 

TinyPortal © 2005-2018