RepositoryItemComboBox.DrawItem Event

Provides the ability to custom paint the items displayed within the combo box editor's drop down.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v20.1.dll

Declaration

[DXCategory("Events")]
public event ListBoxDrawItemEventHandler DrawItem
<DXCategory("Events")>
Public Event DrawItem As ListBoxDrawItemEventHandler

Event Data

The DrawItem event's data class is ListBoxDrawItemEventArgs. The following properties provide information specific to this event:

Property Description
AllowDrawSkinBackground Gets or sets whether the item background is colored according to the currently applied skin.
Appearance Gets the appearance settings used to paint the item currently being processed.
Bounds Gets the bounding rectangle of the item being painted.
Cache Gets an object which specifies the storage for the most used pens, fonts and brushes.
Graphics Gets an object used to paint an item.
Handled Gets or sets a value specifying whether default painting is required.
Index Gets the index of the item being painted.
Item Gets the value of the processed item.
State Gets the state of the item being painted.

Remarks

Handle the DrawItem event to override the default item painting. This event is raised each time an item is about to be painted. The event parameter's properties allow you to identify the processed item, its boundaries, state, appearance settings, etc. You must set the ListBoxDrawItemEventArgs.Handled property to true to override the default painting.

The editor's ComboBoxEdit.DrawItem event is equivalent to the current event.

Examples

The following sample code handles the ComboBoxEdit.DrawItem event to custom paint the currently selected item. The result is shown in the image below:

ComboBoxEdit_DrawItem

using System.Drawing.Drawing2D;
using DevExpress.XtraEditors;

private void comboBoxEdit1_DrawItem(object sender, ListBoxDrawItemEventArgs e) {
  if(e.State != DrawItemState.Selected) return;
    using(var backBrush = new LinearGradientBrush(e.Bounds, Color.Blue, Color.LightBlue,
            LinearGradientMode.Horizontal))
        e.Cache.FillRectangle(backBrush, e.Bounds);
    e.Cache.DrawString(e.Item.ToString(), e.Appearance.Font, Brushes.White,
        e.Bounds);
    e.Handled = true;
}
See Also