Back to Devexpress

RepositoryItemComboBox.CustomizeItem Event

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemcombobox-9c7c5b2f.md

latest3.7 KB
Original Source

RepositoryItemComboBox.CustomizeItem Event

Allows you to customize templated items dynamically.

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Behavior")]
public event CustomizeComboBoxItemEventHandler CustomizeItem
vb
<DXCategory("Behavior")>
Public Event CustomizeItem As CustomizeComboBoxItemEventHandler

Event Data

The CustomizeItem event's data class is DevExpress.XtraEditors.Repository.CustomizeComboBoxItemEventArgs.

Remarks

A ComboBoxEdit control can render its items based on HTML-CSS templates that you can create with the RepositoryItemComboBox.HtmlTemplates property at design time or in code.

The CustomizeItem event fires for each templated item that is about to be displayed. A template typically consists of one or more elements. You can access and customize these template elements while handling the CustomizeItem event.

Use the event’s e.HtmlElement parameter to access individual HTML template elements. The following methods allow you to retrieve HTML elements by tag, class, and ID:

  • HtmlElement.FindElementsByTag — Returns a list of HTML elements that have the specified tag.
  • HtmlElement.FindElementsByClass — Returns a list of HTML elements that are of the specified class.
  • HtmlElement.FindElementById — Returns an HTML element with the specified ID.

The elements returned by these methods expose properties to change element display settings. The main properties include:

  • element.Hidden — Allows you to hide the element.
  • element.Style — Allows you to modify CSS style properties applied to the element. This object exposes the SetBackgroundColor, SetForeColor, and SetProperty methods for this purpose.

Example

The following example changes the background color of a ‘status’ HTML element:

csharp
void comboBoxEdit1_Properties_CustomizeItem(object sender, CustomizeComboBoxItemEventArgs e) {
    var statusBadge = e.HtmlElement?.FindElementById("status");
    bool online = employeesOnline[e.Index];
    if(statusBadge != null && online)
        statusBadge.Style.SetBackgroundColor("@Green");
}
vb
Private Sub ComboBoxEdit1_Properties_CustomizeItem(ByVal sender As Object, ByVal e As XtraEditors.CustomizeTemplatedItemEventArgs)
    Dim statusBadge = e.HtmlElement?.FindElementById("status")
    Dim online As Boolean = employeesOnline(e.Index)
    If statusBadge IsNot Nothing AndAlso online Then statusBadge.Style.SetBackgroundColor("@Green")
End Sub

See Also

CustomItemTemplate

HtmlTemplates

RepositoryItemComboBox Class

RepositoryItemComboBox Members

DevExpress.XtraEditors.Repository Namespace