Token in Windows Forms ComboBox (SfComboBox)
27 Apr 2021 / 2 minutes to read
Token represents the selected item(s) in combobox. The selected items are displayed in rounded-polygon shape with close icon. This option also helps to select multiple items without using check box and remove the token at run time.
sfComboBox1.EnableToken = true;
sfComboBox1.EnableToken = True
The important characteristics of the token support are as follows.
- Items can be searched from the combobox by entering appropriate characters in the text area.
- When an item is selected from the combobox, the item will be added as token in text area and removed from the drop-down area.
- By clicking the remove icon, the appropriate item will be removed from the text area, and it will be added automatically back to the drop-down area.
- Text area height will be increased automatically based on the placement of the selected items.
The appearance of token can be customized using the TokenStyle property. It includes the background color, border color, foreground color, close button color, and font.
sfComboBox1.Style.TokenStyle.BackColor = Color.Aqua; sfComboBox1.Style.TokenStyle.BorderColor = Color.Red; sfComboBox1.Style.TokenStyle.ForeColor = Color.Black; sfComboBox1.Style.TokenStyle.CloseButtonBackColor = Color.Black; sfComboBox1.Style.TokenStyle.Font = new Font(“Arial”, 10F, FontStyle.Bold);
sfComboBox1.Style.TokenStyle.BackColor = Color.Aqua sfComboBox1.Style.TokenStyle.BorderColor = Color.Red sfComboBox1.Style.TokenStyle.ForeColor = Color.Black sfComboBox1.Style.TokenStyle.CloseButtonBackColor = Color.Black sfComboBox1.Style.TokenStyle.Font = New Font(“Arial”, 10F, FontStyle.Bold)
- Using the Down Arrow, Up Arrow, and Enter keys, item can be selected from the combobox.
- Using the Backspace key, the last positioned token will be removed from the text area.
- When the Esc key is pressed, the drop-down area will be closed if it has been opened already.