RepositoryItemComboBox.MeasureItem Event

Allows you to change the height of specific items in the dropdown window.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v20.1.dll

Declaration

[DXCategory("Events")]
public event MeasureItemEventHandler MeasureItem
<DXCategory("Events")>
Public Event MeasureItem As MeasureItemEventHandler

Event Data

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

Property Description
Graphics Gets the Graphics object to measure against.
Index Gets the index of the item for which the height and width is needed.
ItemHeight Gets or sets the height of the item specified by the Index.
ItemWidth Gets or sets the width of the item specified by the Index.

Remarks

The MeasureItem event fires for each item in the dropdown. It allows you to change the height of specific items with the ItemHeight event parameter. If you want to set the height for all items to a specific value, use the RepositoryItemComboBox.DropDownItemHeight property instead.

The MeasureItem event fires before an item is drawn. You can provide custom heights for items via the MeasureItem event and then, if required, custom paint the items by handling the ComboBoxEdit.DrawItem event.

NOTE

It is not possible to change an item width with the MeasureItem event, as the item width is controlled by the popup window width. See RepositoryItemPopupBase.PopupFormSize.

Examples

The following example shows how to set a custom height for items in a ComboBoxEdit control by handling the RepositoryItemComboBox.MeasureItem event.

In this example, if a specific item contains a NewLine character ("\r\n" in C#), its height is doubled to fully display the item's text.

ComboBox_MeasureItem_ex

using DevExpress.XtraEditors;
private void comboBoxEdit1_Properties_MeasureItem(object sender, MeasureItemEventArgs e) {
    ComboBoxEdit cb = sender as ComboBoxEdit;
    string itemValue = (string)cb.Properties.Items[e.Index];
    if (itemValue.Contains("\r\n"))
        e.ItemHeight = e.ItemHeight * 2;            
}
See Also