ItemsView.CustomizeItem Event
Allows you to customize individual items.
Namespace: DevExpress.XtraGrid.Views.Items
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
Event Data
The CustomizeItem event's data class is DevExpress.XtraGrid.Views.Items.CustomizeItemArgs.
Remarks
You can handle the ItemCustomize
event to dynamically modify individual items in the ItemsView. The ItemCustomize
event fires repeatedly for each visible item.
Use the e.Element
event parameter to access HTML elements of the currently processed item. The following methods allow you to retrieve HTML elements by tag, class, and ID:
Element.FindElementsByTag
— Returns a list of HTML elements that have the specified tag.Element.FindElementsByClass
— Returns a list of HTML elements that are of the specified class.Element.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:
HtmlElement.Hidden
— Allows you to hide (collapse) the element.HtmlElement.Disabled
— Allows you to disable the element.HtmlElement.Style
— Allows you to modify CSS style properties applied to the element. This object exposes theSetBackgroundColor
,SetForeColor
,SetVisibility
(displays an empty region instead of the element), andSetProperty
methods for this purpose.
The following example changes visibility of HTML elements according to custom logic.
You can find the complete code of this sample in the following demo: Chat Client.
//CustomizeItem event handler:
void OnCustomizeItem(object sender, CustomizeItemArgs e) {
//...
if(message.IsLiked) {
var btnLike = e.Element.FindElementById("btnLike");
var btnMore = e.Element.FindElementById("btnMore");
if(btnLike != null && btnMore != null) {
btnLike.Hidden = false;
btnMore.Hidden = true;
}
}
if(message.IsFirstMessageOfBlock)
return;
if(!message.IsOwnMessage) {
var avatar = e.Element.FindElementById("avatar");
if(avatar != null)
//Display an empty region instead of the 'avatar' element.
avatar.Style.SetVisibility(Utils.Html.Internal.CssVisibility.Hidden);
}
//...
}