Owl's Blog on .NET development

Component Owl codes Better ListView control all night so you don't have to.

How To: Dynamically Resize Focused Item

Better ListView 2.4.0 now supports setting MaximumTextLines property on every item and sub-item, so you can have multi-line items each with different number text lines:

Dynamic resizing of the focused item

Dynamic resizing of the focused item

We also introduced FocusedItemChanged event, so that you can detect when focus has moved from one element (item / sub-item / group) to another.

These features can be combined to display only the focused item with more details to save space code of the FocusedItemChanged event handler may look like this:

C#

[csharp gutter=”false” toolbar=”false”]
void ListViewFocusedItemChanged(object sender, BetterListViewFocusedItemChangedEventArgs eventArgs)
{
BetterListView listView = (BetterListView)sender;

listView.BeginUpdate();

if (eventArgs.FocusedItemOld != null)
{
// set single line of text for currenly unfocused item
eventArgs.FocusedItemOld.MaximumTextLines = 1;
}

if (eventArgs.FocusedItemNew != null)
{
// set three lines of text for currenly focused item
eventArgs.FocusedItemNew.MaximumTextLines = 3;
}

listView.EndUpdate();
}
[/csharp]

Visual Basic

[vb gutter=”false” toolbar=”false”]
Sub ListViewFocusedItemChanged(sender As Object, eventArgs As BetterListViewFocusedItemChangedEventArgs)
Dim ListView As BetterListView = DirectCast(sender, BetterListView)

ListView.BeginUpdate()

If eventArgs.FocusedItemOld IsNot Nothing Then
‘ set single line of text for currenly unfocused item
eventArgs.FocusedItemOld.MaximumTextLines = 1
End If

If eventArgs.FocusedItemNew IsNot Nothing Then
‘ set three lines of text for currenly focused item
eventArgs.FocusedItemNew.MaximumTextLines = 3
End If

ListView.EndUpdate()
End Sub
[/vb]

Leave a Reply