Skip to main content

BaseListBoxControl.CustomItemTemplate Event

Allows you to assign custom templates to listbox items.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.2.dll

Declaration

[DXCategory("Behavior")]
public event CustomItemTemplateEventHandler CustomItemTemplate

Event Data

The CustomItemTemplate event's data class is DevExpress.XtraEditors.CustomItemTemplateEventArgs.

Remarks

When item templates are enabled, the control’s default behavior is to generate list box items from the default template. The default template is the first element in the BaseListBoxControl.HtmlTemplates collection if this collection is not empty. Otherwise, the default template is the first element in the BaseListBoxControl.Templates collection.

You can handle the CustomItemTemplate event to assign templates to items dynamically, and thus override an item’s default template. You can use the BaseListBoxControl.HtmlTemplates and BaseListBoxControl.Templates 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.

Assign HTML-CSS Templates to Items

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

Example

The following code assigns a custom HTML template (htmlTemplate2) to items that have no images.

private void listBoxControl1_CustomItemTemplate(object sender, DevExpress.XtraEditors.CustomItemTemplateEventArgs e) {
    var item = e.Item as TodoItem;
    if (!item.HasImage)
        e.HtmlTemplate = htmlTemplate2;
}

Assign Regular Templates to Items

To assign a regular template to the item, access this template in the e.Templates or BaseListBoxControl.Templates collection (these collections are equivalent), and assign it to the e.Template event parameter.

HTML-CSS templates have priority over regular templates.

See Also