set id to listbox in gridcontrol

Hi,

after searching the web for hours, I think I need some help.

The setting:
I have a MainForm containing controls for filtering, writing data in a filter table, for example a customer id.
On a SubForm, I have a grid that shows the content of a table; in the table, there’s a field “CustomerID” that is a foreign key pointing to table Customer.
In the grid, the corresponding column “Customer” is a listbox, to display the customers name instead of the ID via SQL command (“select name, ID from customer order by name”).
When I enter data to a new line, it would be nice, if the “Customer” column could be set to a default customer, depending on the customer id from my filter table.

I guess I have to use a macro, triggered when the “customer” field gets the focus, to set the listbox’ value.
Only I cannot identify the method or property I have to use, or even the object on which to use it!

  1. Is there a method to directly set the customer ID, so that the listbox displays the corresponding name, and also will save this ID?
  2. What I have found so far is selecting a name using “event.source.SelectItem(“Smith”,True)”; this does set the displayed name in the listbox, unfortunately, if it loses focus, it switches back to “nothing selected”; is there a confirmation command I have to use?

Any advice would be greatly appreciated!

Hello,

Having a difficult time comprehending the use of this process. Regardless, it is simply a matter of the correct linking between master and sub form. Once you make a selection for your filtering, a refresh button for the sub form should display the correct name in the list box of the sub form table field. No macros needed.

Attached is a sample of this:

Sample ---- LBsubForm.odb

Thank you for the quick response! I will look into it this evening.