×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Combo Boxes question

Combo Boxes question

Combo Boxes question

(OP)
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?

RE: Combo Boxes question

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.

RE: Combo Boxes question

(OP)
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!

RE: Combo Boxes question

A ComboBox has an OnExit method. If you need to perform a task like updating another comboBox, simply attach it to ComboBox1Exit method.

RE: Combo Boxes question

(OP)
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.

RE: Combo Boxes question

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close