1 (edited by joshuA 2023-04-09 02:27:07)

Topic: [SOLVED] Child Combobox Auto-select Single Item

Greetings fellows!
.
I was hoping someone could offer some ideas- as I was unable to find anything on the forum.
.
Here is the situation:

I have two comboboxes and one is a parent.  After the parent (customer) item is selected, WHEN there is only a single (address) child item, I wish for it to be selected automatically by default.  Otherwise, the user will select a desired choice from the multiple items.
.
This is a minor issue, but it would make one less click for user entry lol
.
I have tried many different things, but I am not familiar enough with the order that the OnEvents occur to get the desired result.

  • Manually clicking the button - works as desired

  • OnCloseUp - Doesn't work at all

  • OnChange - Works, but then it unsets the item from the combobox

  • OnClick - Same as above (seems to work better than the others however)

.
I noticed the OnChange seems to click the button twice, perhaps this is because of the child.DoOnChange though...
.
Other things I tried:

  • using DbItemID instead of ItemIndex.  Which is how I have been setting combobox values in the past...

  • changing the DefaultIndex value for the child combobox.

My guess is that this has something to do with the behavior of the parent and child comboboxes.  Or maybe there is a better way?
.
NOTE: In addition to removing the .exe file, I also removed the sqlite.dll because it was over 1MB in each folder and the forum said the file was too large.
.
I appreciate anyone taking a look.
-joshuA

Post's attachments

Attachment icon combobox-events.zip 73.85 kb, 73 downloads since 2023-04-08 

"Energy and persistence conquer all things."

Re: [SOLVED] Child Combobox Auto-select Single Item

Hi Joshua,
Just took a quick look and perhaps you could try it something like the attached.
There was no 'save' action in your example so you might need to check that the relationships are being save correctly.
Probably other ways too - if I think of any, I'll leave a post.
Derek.

Post's attachments

Attachment icon combobox-events2.zip 351.66 kb, 100 downloads since 2023-04-08 

3 (edited by sparrow 2023-04-08 22:12:06)

Re: [SOLVED] Child Combobox Auto-select Single Item

Hi Joshua, Derek


Let the program deal with queries, and we will help with the filter.
Parent canceled, added filter (script) from Custom to Addresses.

Post's attachments

Attachment icon combo filtr.zip 347.25 kb, 102 downloads since 2023-04-09 

Re: [SOLVED] Child Combobox Auto-select Single Item

Derek, I didn't include any of the save stuff in the projects because I was focused on the comboboxes.  Sorry for not clarifying that.
.
So, you both do away with the parent combobox.  Maybe I was using them inappropriately here...
.
Sparrow, I was trying to let the program not only deal with queries, but also with populating the parent child stuff too- oh well.
.
There were techniques in both of your solutions that I hadn't seen, so thank you both for that.
.
Once again, many many thanks to you both!
-joshuA

"Energy and persistence conquer all things."

Re: [SOLVED] Child Combobox Auto-select Single Item

Hi Joshua,
No problem with your understanding of how the parent combobox function should be used.
However, I don't believe you can get the address combobox to automatically populate (as you were asking about when there is just one address)  when you use the parent combobox whereas if you build the address combobox on the fly, then when there is just one address record, it works as you wanted.
As an aside, I much prefer the way that Sparrow used to built it (using combobox.dbfilter) - my way seems rather verbose.
And thanks for providing an example with test data attached - it makes it so much easier when trying to come up with answers.
Derek.

Re: [SOLVED] Child Combobox Auto-select Single Item

Hello again Derek,

No problem with your understanding of how the parent combobox function should be used.

Thanks for clarifying this for me.  I have a habit to second guess myself on these things.  This happened to be one of those exceptions where it wasn't the way to handle what I was after though.
.
I was a bit surprised that no one else has asked this before (at least that I could find).

I much prefer the way that Sparrow used to built it (using combobox.dbfilter) - my way seems rather verbose.

While I agree, I will consider any way that someone is generous enough to suggest- no matter how verbose big_smile
I have learned to always try and let MVD do as much as possible- whenever I am aware of it.  And the dbfilter is one of the things I was referring to above.  I am going to study this approach a bit further for future situations.  Another hidden gem- I'm sure!
.
I did like the way you set focus and added the auto dropdown for the address selection.  Now I have to decide which one to use lol
.
Glad to hear the sample was helpful too- there are some nifty data generators out there.

-joshuA

"Energy and persistence conquer all things."