Back to Devexpress

How to: Change Item's Height in ComboBoxEdit

windowsforms-9473-controls-and-libraries-editors-and-simple-controls-examples-how-to-change-items-height-in-comboboxedit.md

latest1.4 KB
Original Source

How to: Change Item's Height in ComboBoxEdit

  • Oct 25, 2019

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.

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