Back to Devexpress

BaseListBoxControl.MeasureItem Event

windowsforms-devexpress-dot-xtraeditors-dot-baselistboxcontrol-e34f1a0f.md

latest4.4 KB
Original Source

BaseListBoxControl.MeasureItem Event

Provides the ability to change an individual item’s height.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Behavior")]
public event MeasureItemEventHandler MeasureItem
vb
<DXCategory("Behavior")>
Public Event MeasureItem As MeasureItemEventHandler

Event Data

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

PropertyDescription
GraphicsGets the Graphics object to measure against.
IndexGets the index of the item for which the height and width is needed.
ItemHeightGets or sets the height of the item specified by the Index.
ItemWidthGets or sets the width of the item specified by the Index.

Remarks

Handle the MeasureItem event when it is necessary to change height of individual items displayed within the list box control. Note that this event fires before the item is drawn in the BaseListBoxControl.DrawItem event. Thus, you can write an event handler for the MeasureItem event to specify the heights for the items that you are going to draw in your event handler for the BaseListBoxControl.DrawItem event.

Example

The following example shows how to set a custom height for specific items in a ListBoxControl by handling the BaseListBoxControl.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 listBoxControl1_MeasureItem(object sender, MeasureItemEventArgs e) {
    ListBoxControl lb = sender as ListBoxControl;
    string itemValue = (string)lb.Items[e.Index];
    if (itemValue.Contains("\r\n"))
        e.ItemHeight = e.ItemHeight * 2;            
}
vb
Imports DevExpress.XtraEditors

Private Sub ListBoxControl1_MeasureItem(ByVal sender As System.Object, _
  ByVal e As MeasureItemEventArgs) Handles ListBoxControl1.MeasureItem
    Dim lb As ListBoxControl = sender
    Dim itemValue As String = lb.Items(e.Index)
    If (itemValue.Contains(vbCrLf)) Then e.ItemHeight = e.ItemHeight * 2
End Sub

See Also

DrawItem

ItemHeight

ItemAutoHeight

BaseListBoxControl Class

BaseListBoxControl Members

DevExpress.XtraEditors Namespace