Combo box

from Wikipedia, the free encyclopedia

A combo box , combo box (of English combo box ) or combo box is a control in a graphical user interface (GUI) through which the user can select from predefined options, or make alternative own inputs. The name Combobox is derived from the fact that it can be viewed as a combination of a text field and a list field ( selection list , list box , drop-down menu ). With a combo box, keyboard entries in the text field of the combo box or the selection / modification of one of the specified list entries are therefore possible. Comboboxes are not to be confused with a select box or a dropdown list - these do not allow free user input, so the component of the text field is missing here.

Functionality and design

Which entries - as suggestions for selection by the user - are displayed at which point in time in the list of the combo box depends on the particular application. It also depends on the details of the implementation of the combobox in a computer program whether the visible text field is initially empty or whether a preset value is displayed. The list itself can also initially be empty and only later be auto-completed with the numbers or texts entered in the text field .

The list box combined with the text field is usually a space-saving, one-line so-called drop-down list box that only appears when the associated button is pressed. Strictly speaking, one then speaks of a drop-down combo box .

Application examples

A combo box in the Mozilla Firefox web browser
Database applications
For example, a combobox for the salutation can be used to manage an address database. The default values ​​are 'Mr., Ms., Company', but the processor also has the option of entering specially defined salutations ( e.g. Dr. ).
Address bar in the web browser
A typical example of a combo box is the address bar of a web browser . The Internet address can be entered in the text field; already visited pages can be found in the drop-down list and can be called up again by the user with little effort.
Web applications
The user types something into a text field, which opens a selection list with suggested terms from which the user can choose.
Relationships between data objects
If, for example, in an entry mask for orders u. a. If you have to enter which clerk is responsible for processing, a combo box is often used. The 'opened' box shows the names of possible clerks (from a corresponding database) for input selection. After the selection (and if the order data is only displayed) only the name of the selected clerk is visible; its identifier is stored in the data record of the respective order.

Examples

HTML

In contrast to HTML 4, HTML5 offers the option of defining a selection list:

<input name="anrede" list="anrede" />
<datalist id="anrede">
 <option value="Herr"></option>
 <option value="Frau"></option>
</datalist>

Java

In the Java programming language under Swing , JComboBox is the Combobox GUI component.

If the JComboBox is programmed as non-editable ( setEditable(false)), it behaves like a drop-down list box, just like the AWT component Choice . Sun offers the multi-line list box JList in Swing - but not as a separate drop-down list box, but a "castrated" JComboBox is used.

MS Access

Combo box in MS Access

In the graphical development environment of MS Access , the combo box is created in the entry form (in the example for 'orders') as the element type 'combo box' and used as shown in the adjacent graphic. In this case, the developer specifies (when displaying data from a database) for the combo box u. a. the following properties: width of the box; Number of lines in the box; Data source for the persons to be displayed; Name of the ID in the database PERSON; Name of the foreign key in the data stock ORDER u. v. a.

C #

The following example in the C # programming language shows the implementation of a main window with a combo box and a text field and the link between the selection event and an event handling routine (see event ).

using System.Windows.Forms;

public class MainForm : System.Windows.Forms.Form
{
	// Konstruktor des MainForms.
    public MainForm() : base()
    {
        InitializeComboBox();
        InitializeTextBox();
    }
	
	// Startet die Anwendung und erzeugt das MainForm durch Aufruf des Konstruktors.
    public static void Main()
    {
        Application.Run(new MainForm());
    }
	
    internal System.Windows.Forms.TextBox personTextBox;
	
    // Initialisiert das Textfeld.
    private void InitializeTextBox()
    {
		personTextBox = new System.Windows.Forms.TextBox();
		personTextBox.ScrollBars = ScrollBars.Vertical;
		personTextBox.Location = new System.Drawing.Point(50, 25);
		personTextBox.Size = new System.Drawing.Size(200, 100);
		personTextBox.Text = "Name und Anzahl der Verkommen:";
		personTextBox.Multiline = true; // Legt fest, dass die Textfeld mehrere Zeilen haben kann und Zeilenumbrüche ermöglicht
		Controls.Add(personTextBox);
    }
	
    internal System.Windows.Forms.ComboBox personsComboBox;
    
    // Initialisiert die Combobox und fügt ein Array vom Typ string hinzu.
    private void InitializeComboBox()
    {
        personsComboBox = new System.Windows.Forms.ComboBox();
        string[] personen = new string[]{"Hamilton, David", "Hensien, Kari",
                "Hammond, Maria", "Harris, Keith", "Henshaw, Jeff D.", 
                "Hanson, Mark", "Harnpadoungsataya, Sariya", 
                "Harrington, Mark", "Harris, Keith", "Hartwig, Doris", 
                "Harui, Roger", "Hassall, Mark", "Hasselberg, Jonas", 
                "Harnpadoungsataya, Sariya", "Henshaw, Jeff D.", 
                "Henshaw, Jeff D.", "Hensien, Kari", "Harris, Keith", 
                "Henshaw, Jeff D.", "Hensien, Kari", "Hasselberg, Jonas",
                "Harrington, Mark", "Hedlund, Magnus", "Hay, Jeff", 
                "Heidepriem, Brandon D."};
				
        personsComboBox.Items.AddRange(personen);
        personsComboBox.Location = new System.Drawing.Point(50, 150);
        personsComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
        personsComboBox.Size = new System.Drawing.Size(200, 100);
        personsComboBox.TabIndex = 0;
        Controls.Add(personsComboBox);
        
        // Verknüpft die Ereignisbehandlungsmethode mit dem Auswahlereignis SelectedIndexChanged der Combobox.
        personsComboBox.SelectedIndexChanged += new System.EventHandler(personsComboBox_SelectedIndexChanged);
    }
	
	// Diese Methode wird aufgerufen, wenn der Benutzer die Auswahl der Combobox ändert.
	// Sie sucht alle Vorkommen des Namens der Person im Array und gibt den Namen und die Anzahl der Vorkommen im Textfeld aus.
    private void personsComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        string selectedName = (string) personsComboBox.SelectedItem;
		
        int numberOfOccurences = 0;
        int index = -1;
		
        // Ruft die Methode FindStringExact auf, um das erste Vorkommen in der Liste zu finden.
        index = personsComboBox.FindStringExact(selectedName);
		
		// Entfernt den gefundenen Namen und erhöht die Anzahl der gefundenen Namen.
		// Ruft dann die Methode FindStringExact erneut auf und übergibt den Index des aktuell gefundenen Elements, damit die Suche dort beginnt statt am Anfang der Liste.
		while (index != -1)
        {
            personsComboBox.Items.RemoveAt(index);
            numberOfOccurences += 1;
            index = personsComboBox.FindStringExact(selectedName, index);
        }
        // Update the text in personTextBox.
        personTextBox.Text = personTextBox.Text + "\r\n" + selectedName + ": " + numberOfOccurences;
    }
}

Individual evidence

  1. Microsoft Docs: ComboBox.SelectedIndexChanged Event