Skip to main content
All docs
V24.1

ItemsView.QueryItemTemplate Event

Allows you to assign and customize templates for individual items.

Namespace: DevExpress.XtraGrid.Views.Items

Assembly: DevExpress.XtraGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

[DXCategory("Events")]
public event QueryItemTemplateEventHandler QueryItemTemplate

Event Data

The QueryItemTemplate event's data class is DevExpress.XtraGrid.Views.Items.QueryItemTemplateEventArgs.

Remarks

The QueryItemTemplate event fires repeatedly for each item. The event allows you to override the default template (ItemsView.HtmlTemplate) for individual items. To do this, assign a custom HTML-CSS template (a DevExpress.Utils.Html.HtmlTemplate object) to the e.Template event parameter.

You can also use the following properties to modify the HTML and CSS markup of the current template:

  • e.Template.Template — Specifies HTML markup.
  • e.Template.Styles — Specifies CSS styles.

Tip

The ItemsView’s ItemsView.HtmlTemplates property allows you to create multiple HTML-CSS templates at design time. You can then access these templates in your QueryItemTemplate event handler, and assign them to items.

The following ItemsView.QueryItemTemplate event handler assigns different templates to different items based on an item’s type (IsOwnMessage setting).

You can find the complete code of this sample in the following demo: Chat Client.

void OnQueryItemTemplate(object sender, QueryItemTemplateEventArgs e) {
    var message = e.Row as DevAV.Chat.Model.Message;
    if(message == null)
        return;
    if(message.IsOwnMessage)
        Styles.MyMessage.Apply(e.Template);
    else
        Styles.Message.Apply(e.Template);
    //...
}
See Also