Faq/Base/135

    From The Document Foundation Wiki
    < Faq‎ | Base


    How do I implement a selection dropdown?

    When entering data you want to be able to choose from the list of values ​​already contained in the field. This is possible in Calc text values ​​with a selection list (right click or Alt + Down).

    We would like to have

    Selection from a unique index

    Base provides this, but only with a form.

    • In other words, not with direct entry into the table.
    • To effect this in "table" mode (datasheet), create a form in the data assistant: the lookup then happens via a "control table".

    The technique uses a combobox control whose content type will be Sql and the contents is the required selection.

    SELECT DISTINCT "Instrument" FROM "Table1" ORDER BY "Instrument" ASC

    Notes:

    • The keyword DISTINCT forces the list to omit duplicates.
    • The list is ordered to facilitate searching.
    • It is advisable to add an index on the search field (click on the button "Draft Index" in table editing mode).

    These are the screens to set this up:

    SQL code for the combobox

    Using a combobox control allows the entry of new values. These are instantly taken into account in the list but are added to the end of the list by default until the next data update. Force the update by putting a macro in the On got focus event. The macro should be something like

    option explicit
    Sub PysAcutaliserListe(PysEvent)
    PysEvent.source.model.refresh
    End Sub
    

    Download a database example