state – Owl's Blog on .NET development http://www.componentowl.com/blog Component Owl codes Better ListView control all night so you don't have to. Tue, 04 Sep 2018 13:10:05 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 Read-Only Mode in Better ListView http://www.componentowl.com/blog/read-only-mode-in-better-listview/ http://www.componentowl.com/blog/read-only-mode-in-better-listview/#respond Fri, 27 Jan 2012 16:21:58 +0000 http://www.componentowl.com/blog/?p=482 Better ListView 2.5 introduces a new boolean property called ReadOnly.

When set to true, the Better ListView does not respond to keyboard and mouse input. There are, however, some exceptions that make the Read-only mode different to the Disabled mode (when Enabled property is set to false).

When in Read-only mode, content of the Better ListView can be still scrolled (the scroll bars are enabled) and groups/items can be expanded/collapsed.

The difference between Disabled and Read-only can be seen on the following images:

Normal state

Normal state

Disabled state

Disabled state

Read-only state

Read-only state

 

As you can see, the Better ListView is displayed normally in Read-only mode, but the group header does not have a hot state (because cannot be focused). Items also cannot be focused or selected, but the expand buttons are still interactive.

The scroll bars would also be enabled and can be used, which is different from Disabled mode where everything is grayed and cannot be used.

]]>
http://www.componentowl.com/blog/read-only-mode-in-better-listview/feed/ 0
How to Display Items in Custom States http://www.componentowl.com/blog/how-to-display-items-in-custom-states/ http://www.componentowl.com/blog/how-to-display-items-in-custom-states/#respond Tue, 15 Nov 2011 15:24:25 +0000 http://www.componentowl.com/blog/?p=398 One of our customers recently asked us if it is possible in Better ListView to draw item highlighted even when the control loses focus. This is an interesting and useful feature, so we implemented it right away.

Owner drawing in Better ListView 2.3.0 and higher allows you to draw elements (column headers, items, sub-items and groups) in any state you wish (hot, selected, focused and any combination of the three).

For example, we would like to highlight several items in one Better ListView depending on hovered item in other Better ListView:

Better ListView shows multiple hot items

Better ListView shows multiple hot items

Items can be also be drawn as if the control is focused, enabled or disabled. This feature can be applied when you wish to display items in highlighted state even if Better ListView is not focused:

Better ListView keeps selected items highlighted

Better ListView keeps selected items highlighted

We implemented the first sample (showing mulitple hot items) by inheriting from BetterListView, making a new class called HotListView. The implementation is very simple:

 

C#

[csharp gutter=”false” toolbar=”false”]
public class HotListView : BetterListView
{
public HashSet HotItems
{
get
{
return this.hotItems;
}
set
{
this.hotItems = value;

Refresh();
}
}

private HashSethotItems = new HashSet();

protected override void OnDrawItem(BetterListViewDrawItemEventArgs eventArgs)
{
if (this.hotItems.Contains(eventArgs.Item.Index))
{
eventArgs.ItemStateInfo = new BetterListViewItemStateInfo(
eventArgs.ItemStateInfo.ItemState | BetterListViewItemState.Hot,
eventArgs.ItemStateInfo.ExpandButtonState,
eventArgs.ItemStateInfo.CheckBoxState);
}

base.OnDrawItem(eventArgs);
}
}
[/csharp]

Visual Basic

[vb gutter=”false” toolbar=”false”]
Public Class HotListView
Inherits BetterListView
Public Property HotItems() As HashSet(Of Integer)
Get
Return Me.m_hotItems
End Get
Set
Me.m_hotItems = value

Refresh()
End Set
End Property

Private m_hotItems As New HashSet(Of Integer)()

Protected Overrides Sub OnDrawItem(eventArgs As BetterListViewDrawItemEventArgs)
If Me.m_hotItems.Contains(eventArgs.Item.Index) Then
eventArgs.ItemStateInfo = New BetterListViewItemStateInfo(eventArgs.ItemStateInfo.ItemState Or BetterListViewItemState.Hot, eventArgs.ItemStateInfo.ExpandButtonState, eventArgs.ItemStateInfo.CheckBoxState)
End If

MyBase.OnDrawItem(eventArgs)
End Sub
End Class
[/vb]

 

The HotListView contains one property called HotItems. When drawing items (OnDrawItem method), it looks whether the item is in the HotItems set. If so, item drawing state is altered so that the item will be drawn as hot.

The modified ListView for second sample is even simpler. We call it HighlightListView:

 

C#

[csharp gutter=”false” toolbar=”false”]
public class HighlightListView : BetterListView
{
protected override void OnDrawItem(BetterListViewDrawItemEventArgs eventArgs)
{
if ((eventArgs.ItemStateInfo.ItemState & BetterListViewItemState.Selected) == BetterListViewItemState.Selected)
{
// if the item is selected, always draw control as if it is focused
eventArgs.DrawFocused = true;
}

base.OnDrawItem(eventArgs);
}
}
[/csharp]

Visual Basic

[vb gutter=”false” toolbar=”false”]
Public Class HighlightListView
Inherits BetterListView
Protected Overrides Sub OnDrawItem(eventArgs As BetterListViewDrawItemEventArgs)
If (eventArgs.ItemStateInfo.ItemState And BetterListViewItemState.Selected) = BetterListViewItemState.Selected Then
‘ if the item is selected, always draw control as if it is focused
eventArgs.DrawFocused = True
End If

MyBase.OnDrawItem(eventArgs)
End Sub
End Class
[/vb]

 

This modification only draws selected items as if the control is always focused.

UPDATE: From Better ListView 2.3.1, you can simply use HideSelectionMode property to keep selected items highlighted.

]]>
http://www.componentowl.com/blog/how-to-display-items-in-custom-states/feed/ 0