windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemcombobox-e763cae2.md
Allows you to change the height of specific items in the dropdown window.
Namespace : DevExpress.XtraEditors.Repository
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event MeasureItemEventHandler MeasureItem
<DXCategory("Events")>
Public Event MeasureItem As MeasureItemEventHandler
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. |
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.
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.
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;
}
Imports DevExpress.XtraEditors
Private Sub ComboBoxEdit1_Properties_MeasureItem(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MeasureItemEventArgs) _
Handles ComboBoxEdit1.Properties.MeasureItem
Dim cb As ComboBoxEdit = sender
Dim itemValue As String = cb.Properties.Items(e.Index)
If (itemValue.Contains(vbCrLf)) Then e.ItemHeight = e.ItemHeight * 2
End Sub
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.
winforms-combobox-hide-specific-items/CS/MyComboBoxEdit/ComboBoxHideItemsHelper.cs#L33
_itemMeasure = new MeasureItemEventHandler(OnMeasureItem);
_comboBox.Properties.MeasureItem += _itemMeasure;
}
winforms-combobox-hide-specific-items/VB/MyComboBoxEdit/ComboBoxHideItemsHelper.vb#L41
_itemMeasure = New MeasureItemEventHandler(AddressOf OnMeasureItem)
AddHandler _comboBox.Properties.MeasureItem, _itemMeasure
End If
See Also