Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Boxes question

Status
Not open for further replies.

Baldur3635

Technical User
Feb 15, 2010
26
BE
I have 2 x ComboBoxes.

CB1 has a list of items. CB2 has a list of matching item codes.

My idea is that the user select an Item from the DB1. I find the ItemIndex (no problem) and then use this number to select the corresponding Item Code.

Ive been looking at doing this. It seems so easy, but which event ob CB1 should I use to get the itemIndex, and how . when would I use this number to get the ItemCode from CB2?

I could also create an CONST array with both items and codes <200 OR I could create a Lookup DB. I guess I could also create a file with both items.

I quite fancy using the CBs, but in the long run, which would be best?

 
The typical way something like this is done is creating the constant array of items with an index range consistent with the combobox and then referencing that. Use OnChange of the Combobox to set this itemcode value from what is selected in the combobox.

Of course this changes if you're getting data from a file or other source, but that's the basic idea. Select combobox, then look up associated data.

 
The solution was so simple, I could hardly believe that it took me so long to think of it.

It just takes ONE line :

cxDBComboBox2.ItemIndex := cxDBComboBox1.ItemIndex;

There's just a small snag that eludes me.

If I select an item in Box1 and then move to the next field (not entering the Box2. It updates the database correctly.

If I don't move to another item even though the box2 data is correct, it doesn't show in the box.

I'm trying to think how I can refresh Box2 as soon as I leave Box1 So far, no luck. I'm missing something obvious!
 
A ComboBox has an OnExit method. If you need to perform a task like updating another comboBox, simply attach it to ComboBox1Exit method.
 
Hi majlumbo Thanks for the tip. You are correct, BUT it actually does, but it doesn't. You have to actually click on some other EditBox before it changes (on screen). My problem was that this was the last box to have focus before commit.

I solved the problem by changing the form layout so that a different field was the last entry.
 
Then it may be solved by attaching the code to the combobox's OnChange event. That way it fires when a new item is selected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top