BaseListBoxControl.CustomItemDisplayText Event
Enables custom display text to be provided for control items.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v24.2.dll
Declaration
[DXCategory("Behavior")]
public event CustomItemDisplayTextEventHandler CustomItemDisplayText
Event Data
The CustomItemDisplayText event's data class is DevExpress.XtraEditors.CustomItemDisplayTextEventArgs.
Remarks
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:
- Item provides access to the item being processed;
- Value contains the value of the current item. To provide custom display text for this value, you can format the value according to your needs and then assign the string to the DisplayText property;
- Index gets the zero-based index of the item;
- DisplayText allows you to customize the display text of the item being processed.
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() + ")";
}
See Also