windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-b7751821.md
Allows you to replace the UI for the Excel-styled menus’ “Values” tab. Also affects editors generated by the Filtering UI Context component attached to this Data Grid.
Namespace : DevExpress.XtraGrid.Views.Base
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("Appearance")]
public event FilterPopupExcelPrepareTemplateEventHandler FilterPopupExcelPrepareTemplate
<DXCategory("Appearance")>
Public Event FilterPopupExcelPrepareTemplate As FilterPopupExcelPrepareTemplateEventHandler
The FilterPopupExcelPrepareTemplate event's data class is DevExpress.XtraGrid.Views.Grid.FilterPopupExcelPrepareTemplateEventArgs.
The FilterPopupExcelPrepareTemplate event allows you to change the items’ visual representation only. To modify the items themselves, handle the ColumnView.FilterPopupExcelData event instead.
In the example below, the FilterPopupExcelPrepareTemplate event replaces a default checked list box with a custom “TileList” control.
using DevExpress.Utils.Filtering;
using DevExpress.Utils.Controls;
//replace the filter panel template
private void GridView1_FilterPopupExcelPrepareTemplate(object sender, DevExpress.XtraGrid.Views.Grid.FilterPopupExcelPrepareTemplateEventArgs e) {
if (e.PropertyPath == "CategoryID")
e.Template = new TileList() { Images = categoryImages };
}
//a custom TileList control that replaces default check lists
public partial class TileList : XtraUserControl, IXtraResizableControl {
public TileList() {
InitializeComponent();
Part_Values.CustomizeItem += PART_Values_CustomizeItem;
}
public SvgImageCollection Images {
get;
set;
}
public Size ImageSize {
get { return new Size(Part_Values.ItemHeight - 8, Part_Values.ItemHeight - 8); }
set { Part_Values.ItemHeight = Math.Max(40, value.Height + 8); }
}
protected override void OnParentChanged(System.EventArgs e) {
base.OnParentChanged(e);
if(Parent != null)
Part_Values.BackColor = FindForm().BackColor;
}
void PART_Values_CustomizeItem(object sender, CustomizeTemplatedItemEventArgs e) {
if(Images == null)
return;
var tileElement = e.TemplatedItem.Elements[0];
if(e.Value is Enum) {
tileElement.Image = Images.GetImage(e.Value.ToString().ToLowerInvariant(), ImageSize);
return;
}
if(e.Value is int) {
tileElement.Image = Images.GetImage((int)e.Value, ImageSize);
return;
}
tileElement.Image = Images.GetImage("all", ImageSize);
}
Size IXtraResizableControl.MaxSize {
get { return new Size(0, GetHeight()); }
}
Size IXtraResizableControl.MinSize {
get { return new Size(0, GetHeight()); }
}
int GetHeight() {
return (Part_Values.Items.Count > 0) ? Part_Values.CalcBestSize().Height : Part_Values.ItemHeight;
}
}
Imports DevExpress.Utils.Filtering
Imports DevExpress.Utils.Controls
//replace the filter panel template
Private Sub GridView1_FilterPopupExcelPrepareTemplate(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.FilterPopupExcelPrepareTemplateEventArgs)
If e.PropertyPath = "CategoryID" Then
e.Template = New TileList() With {.Images = categoryImages}
End If
End Sub
'a custom TileList control that replaces default check lists
Partial Public Class TileList
Inherits XtraUserControl
Implements IXtraResizableControl
Public Sub New()
InitializeComponent()
AddHandler Part_Values.CustomizeItem, AddressOf PART_Values_CustomizeItem
End Sub
Public Property Images() As SvgImageCollection
Public Property ImageSize() As Size
Get
Return New Size(Part_Values.ItemHeight - 8, Part_Values.ItemHeight - 8)
End Get
Set(ByVal value As Size)
Part_Values.ItemHeight = Math.Max(40, value.Height + 8)
End Set
End Property
Protected Overrides Sub OnParentChanged(ByVal e As System.EventArgs)
MyBase.OnParentChanged(e)
If Parent IsNot Nothing Then
Part_Values.BackColor = FindForm().BackColor
End If
End Sub
Private Sub PART_Values_CustomizeItem(ByVal sender As Object, ByVal e As CustomizeTemplatedItemEventArgs)
If Images Is Nothing Then
Return
End If
Dim tileElement = e.TemplatedItem.Elements(0)
If TypeOf e.Value Is System.Enum Then
tileElement.Image = Images.GetImage(e.Value.ToString().ToLowerInvariant(), ImageSize)
Return
End If
If TypeOf e.Value Is Integer Then
tileElement.Image = Images.GetImage(CInt(Math.Truncate(e.Value)), ImageSize)
Return
End If
tileElement.Image = Images.GetImage("all", ImageSize)
End Sub
Private ReadOnly Property IXtraResizableControl_MaxSize() As Size Implements IXtraResizableControl.MaxSize
Get
Return New Size(0, GetHeight())
End Get
End Property
Private ReadOnly Property IXtraResizableControl_MinSize() As Size Implements IXtraResizableControl.MinSize
Get
Return New Size(0, GetHeight())
End Get
End Property
Private Function GetHeight() As Integer
Return If(Part_Values.Items.Count > 0, Part_Values.CalcBestSize().Height, Part_Values.ItemHeight)
End Function
End Class
See Also
FilterPopupExcelCustomizeTemplate