Back to Devexpress

BaseListBoxControl.ItemAutoHeight Property

windowsforms-devexpress-dot-xtraeditors-dot-baselistboxcontrol-96bcbb90.md

latest5.0 KB
Original Source

BaseListBoxControl.ItemAutoHeight Property

Gets or sets whether item height is automatically calculated to fit item contents. In auto-height mode, different items may have different heights.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(false)]
[DXCategory("Layout")]
public bool ItemAutoHeight { get; set; }
vb
<DefaultValue(False)>
<DXCategory("Layout")>
Public Property ItemAutoHeight As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

true if item height is automatically calculated; otherwise, false.

|

Remarks

All items initially have the same height, determined by the control’s font. To specify a custom item height, use the ItemHeight property or MeasureItem event.

The ListBoxControl can calculate item height based on content. The options that enable this behavior depend on whether you use item templates.

Regular items

Do the following to enable automatic height calculation:

You can increase the automatically calculated height with the ItemHeight property.

Template-based items

Follow the steps below to enable automatic height calculation:

  • Enable the BaseListBoxControl.ItemAutoHeight property.
  • Enable the TableRowDefinition.AutoHeight setting for required rows in the ListBoxControl’s item template.

Example

The following example enables automatic item height calculation for a sample template-based ListBoxControl. The example allows the row that contains a Notes element to automatically adjust its height. In addition, the code sets the MaxLineCount property to limit the maximum height of the Notes element.

csharp
listBoxControl1.ItemAutoHeight = true;
listBoxControl1.Templates[0].Rows[2].AutoHeight = true;
TemplatedItemElement noteElement = listBoxControl1.Templates[0].Elements["Notes"];
noteElement.MaxLineCount = 9;
vb
ListBoxControl1.ItemAutoHeight = True
ListBoxControl1.Templates[0].Rows[2].AutoHeight = True
Dim noteElement As TemplatedItemElement = listBoxControl1.Templates[0].Elements("Notes")
noteElement.MaxLineCount = 9

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

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-listbox-item-templates-enable-word-wrap/CS/dxSample/Form1.cs#L8

csharp
InitializeComponent();
regularTemplateListBox.ItemAutoHeight = true;
htmlTemplateListBox.ItemAutoHeight = true;

winforms-listbox-item-templates-enable-word-wrap/VB/dxSample/Form1.vb#L10

vb
InitializeComponent()
regularTemplateListBox.ItemAutoHeight = True
htmlTemplateListBox.ItemAutoHeight = True

See Also

ItemHeight

BaseListBoxControl Class

BaseListBoxControl Members

DevExpress.XtraEditors Namespace