windowsforms-devexpress-dot-xtraeditors-dot-baselistboxcontrol-4f7e6e80.md
Enables custom display text to be provided for control items.
Namespace : DevExpress.XtraEditors
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Behavior")]
public event CustomItemDisplayTextEventHandler CustomItemDisplayText
<DXCategory("Behavior")>
Public Event CustomItemDisplayText As CustomItemDisplayTextEventHandler
The CustomItemDisplayText event's data class is DevExpress.XtraEditors.CustomItemDisplayTextEventArgs.
The CustomItemDisplayText event allows you to provide custom display text for control items. The CustomItemDisplayTextEventArgs object, passed to the event handler, exposes the following properties:
The code below illustrates how to replace RGB values with color names, if such values are present among KnownColors.
using DevExpress.XtraEditors;
using System.Drawing;
void OnCustomItemDisplayText(object sender, CustomItemDisplayTextEventArgs e) {
// Create a Color from string values
string[] colorValues = e.DisplayText.Split(',');
for (int i = 0; i < colorValues.Length; i++) colorValues[i] = colorValues[i].Trim(' ');
Color color =
Color.FromArgb(255, int.Parse(colorValues[0]), int.Parse(colorValues[1]), int.Parse(colorValues[2]));
// Search for the RGB value in known colors, and return a color name if found
bool colorFound = false;
foreach (var colorValue in Enum.GetValues(typeof(KnownColor))) {
Color knownColor = Color.FromKnownColor((KnownColor)colorValue);
if (knownColor.A == color.A && knownColor.R == color.R &&
knownColor.G == color.G && knownColor.B == color.B) {
e.DisplayText = knownColor.Name + " (" + e.Value.ToString() + ")";
colorFound = true;
break;
}
}
if (!colorFound) e.DisplayText = "Unknown (" + e.Value.ToString() + ")";
}
Imports DevExpress.XtraEditors
Imports System.Drawing
Private Sub OnCustomItemDisplayText(ByVal sender As Object, ByVal e As CustomItemDisplayTextEventArgs)
' Create a Color from string values
Dim colorValues() As String = e.DisplayText.Split(","c)
For i As Integer = 0 To colorValues.Length - 1
colorValues(i) = colorValues(i).Trim(" "c)
Next i
Dim color As Color = Color.FromArgb(255, Integer.Parse(colorValues(0)), Integer.Parse(colorValues(1)), Integer.Parse(colorValues(2)))
' Search for the RGB value in known colors, and return a color name if found
Dim colorFound As Boolean = False
For Each colorValue In System.Enum.GetValues(GetType(KnownColor))
Dim knownColor As Color = Color.FromKnownColor(CType(colorValue, KnownColor))
If knownColor.A = color.A AndAlso knownColor.R = color.R AndAlso knownColor.G = color.G AndAlso knownColor.B = color.B Then
e.DisplayText = knownColor.Name & " (" & e.Value.ToString() & ")"
colorFound = True
Exit For
End If
Next colorValue
If Not colorFound Then
e.DisplayText = "Unknown (" & e.Value.ToString() & ")"
End If
End Sub
See Also