windowsforms-devexpress-dot-xtraeditors-dot-baselistboxcontrol-96bcbb90.md
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
[DefaultValue(false)]
[DXCategory("Layout")]
public bool ItemAutoHeight { get; set; }
<DefaultValue(False)>
<DXCategory("Layout")>
Public Property ItemAutoHeight As Boolean
| Type | Default | Description |
|---|---|---|
| Boolean | false |
true if item height is automatically calculated; otherwise, false.
|
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.
Do the following to enable automatic height calculation:
You can increase the automatically calculated height with the ItemHeight property.
Follow the steps below to enable automatic height calculation:
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.
listBoxControl1.ItemAutoHeight = true;
listBoxControl1.Templates[0].Rows[2].AutoHeight = true;
TemplatedItemElement noteElement = listBoxControl1.Templates[0].Elements["Notes"];
noteElement.MaxLineCount = 9;
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
InitializeComponent();
regularTemplateListBox.ItemAutoHeight = true;
htmlTemplateListBox.ItemAutoHeight = true;
winforms-listbox-item-templates-enable-word-wrap/VB/dxSample/Form1.vb#L10
InitializeComponent()
regularTemplateListBox.ItemAutoHeight = True
htmlTemplateListBox.ItemAutoHeight = True
See Also