Skip to main content

RepositoryItemComboBox.MeasureItem Event

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

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Events")]
public event MeasureItemEventHandler MeasureItem

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.

Example

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;            
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the MeasureItem event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also