Back to Devexpress

RepositoryItemComboBox.CustomItemTemplate Event

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemcombobox-0988ff0a.md

latest3.3 KB
Original Source

RepositoryItemComboBox.CustomItemTemplate Event

Allows you to assign custom HTML-CSS templates to combo box items.

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

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

Event Data

The CustomItemTemplate event's data class is DevExpress.XtraEditors.Repository.CustomComboBoxItemTemplateEventArgs.

Remarks

When HTML-CSS templates are enabled, the control’s default behavior is to generate combo box items from the default template. The default template is the first element in the RepositoryItemComboBox.HtmlTemplates collection.

You can handle the CustomItemTemplate event to assign templates to items dynamically, and thus override an item’s default template. Use the RepositoryItemComboBox.HtmlTemplates collections to create item templates beforehand.

The currently processed item can be identified with the following properties:

  • e.Index — Specifies the item’s zero-based index in the item collection.
  • e.Item — Specifies the item’s underlying data object.

To assign an HTML-CSS template to the currently processed item, access the required template (for example, from the RepositoryItemComboBox.HtmlTemplates collection), and assign it to the e.HtmlTemplate event parameter.

csharp
void comboBoxEdit1_Properties_CustomItemTemplate(object sender, CustomComboBoxItemTemplateEventArgs e) {
    var item = e.DataItem as TodoItem;
    if (!item.HasImage)
        e.HtmlTemplate = htmlTemplate2;
}
vb
Private Sub ComboBoxEdit1_Properties_CustomItemTemplate(sender As Object, e As DevExpress.XtraEditors.CustomItemTemplateEventArgs) _
    Handles ComboBoxEdit1.CustomItemTemplate
    Dim item = TryCast(e.DataItem, TodoItem)
    If Not item.HasImage Then
        e.HtmlTemplate = htmlTemplate2
    End If
End Sub

See Also

CustomizeItem

HtmlTemplates

RepositoryItemComboBox Class

RepositoryItemComboBox Members

DevExpress.XtraEditors.Repository Namespace