Files

280 lines
11 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Item Hierarchy</title>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="prettify.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="prettify.js"></script><script type="text/javascript" src="lang-vb.js"></script><link href="../resources/main.css" media="screen" rel="stylesheet" type="text/css">
</head>
<body onload="prettyPrint()"><div class="placing">
<br><table class="navigation"><tr>
<td class="navigation-previous"><a href="chapter-insertion-mark.html"><strong>
« Insertion Mark</strong></a></td>
<td class="navigation-index"><a href="../../../better-listview-express/documentation.html"><strong>Index</strong></a></td>
<td class="navigation-next"><a href="chapter-item-reorder.html"><strong>Item Reordering »
</strong></a></td>
</tr></table>
<br><h1>Item Hierarchy</h1>
<div class="banner">
<a href="../../../blog/page/6/index.html"><img src="../resources/overview.gif" alt="Better ListView" class="ss"></a>
<div class="inside">
<div class="text">Better ListView: Ultimate .NET ListView replacement control for WinForms (C#, VB.NET)</div>
<span class="dbtn-c dbtn-hilight"><span class="dbtn-w"><a href="../../../betterlistview.exe" class="dbtn">Download</a></span></span>
<span class="dbtn-c"><span class="dbtn-w"><a href="../../../blog/page/6/index.html" class="dbtn">More Info</a></span></span>
</div>
</div>
<br><hr>
<p class="note">Item hierarchy is not supported in <strong><em>Better ListView
Express</em></strong>.</p>
<hr>
<br><p>Items can be organized in tree structure by using
<span class="code">BetterListViewItem.ChildItems</span> collection. Simply add items as
other item's children to create a parent-child relationship:</p>
<p class="images"><img src="item-hierarchy-overview.png"></p>
<p>Hierarchical items can be used in combination with columns and <strong><em><a href="chapter-groups.html">Groups</a></em></strong>:</p>
<p class="images"><img src="item-hierarchy-groups.png"></p>
<p>Child items can use sub-items as well.</p>
<p>Parent items can be collapsed and expanded through expand buttons.
Expand buttons appear automatically when there are any children. Expand
buttons can be disabled on all items using
<span class="code">ShowItemExpandButtons</span> property or individually using
<span class="code">BetterListViewItem.AllowShowExpandButton</span>.</p>
<h2>Adjusting Indentation</h2>
<p>By default, the child items have indentation of an expand button
size. Indentation can be adjusted by settings <span class="code">Indent</span> property
to any non-negative value (the indentation unit is pixels). To resume
default indentation, set the property to
<span class="code">BetterListView.DefaultIndent</span>. Following images show effect of
different indentation:</p>
<p class="images"><img src="item-hierarchy-indent-small.png"><img src="item-hierarchy-indent-large.png"></p>
<h2>Traversing Hierarchical Items</h2>
<p><span class="code">BetterListViewItem</span> implements <span class="code">IEnumerable</span>
interface to allow traversing through all its child items in a foreach
cycle:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">foreach (BetterListViewItem itemChild in items)
{
// ...
}</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">For Each itemChild As BetterListViewItem In items
' ...
Next</code></pre>
<p>The same is possible on whole <span class="code">BetterListView</span>; it also
implements <span class="code">IEnumerable</span> to enumerate all items within the
list, including child items.</p>
<h2>Navigation in Hierarchy</h2>
<p>Multiple levels of hierarchy are possible.
<span class="code">BetterListViewItem</span> has following properties for easy
navigation in item hierarchy:</p>
<ul style="list-style:none">
<li>
<span class="code">Address</span><ul style="list-style:none"><li>
<p>Location of the item within hierarchy.</p>
</li></ul>
</li>
<li>
<span class="code">ChildItems</span><ul style="list-style:none"><li>
<p>Child items of the item.</p>
</li></ul>
</li>
<li>
<span class="code">LastAvailableChildItem</span><ul style="list-style:none"><li>
<p>The last (bottom) child item that can be scrolled into
view.</p>
</li></ul>
</li>
<li>
<span class="code">Level</span><ul style="list-style:none"><li>
<p>Item level in hierarchy (the top level is 0).</p>
</li></ul>
</li>
<li>
<span class="code">ParentItem</span><ul style="list-style:none"><li>
<p>Parent item of the item (one level up).</p>
</li></ul>
</li>
</ul>
<h2>
<a name="addressing-elements" id="addressing-elements"></a>Addressing Elements</h2>
<p>Since Better ListView supports <strong><em><a href="chapter-item-hierarchy.html">Hierarchical items</a></em></strong> there
is a need for addressing items on different levels of hierarchy. When
using only the Items list, <span class="code">BetterListViewItem.Index</span> property
is sufficient. Child items (contained in
<span class="code">BetterListViewItem.ChildItems </span>collection) has its own
indices, so there can be several items with <span class="code">Index</span> property
equal to <span class="code">0</span>, for example. To localize every element (item or
group) uniquely, use the <span class="code">Address</span> property:</p>
<ul>
<li>
<p><span class="code">BetterListViewGroup.Address</span></p>
</li>
<li>
<p><span class="code">BetterListViewItem.Address</span></p>
</li>
</ul>
<p>Address is a structure that can be represented as string (via
<span class="code">ToString</span> method) or parsed from such string. Element address
looks like this:</p>
<pre>5:7.3</pre>
<p>The first number followed by colon (prefix) is a group index. The
rest of numbers represent indices of items and child items separated by
periods (in this case: <strong><em>item with index 3, which is a child item
of item with index 7</em></strong>).</p>
<p>If there are no groups, the prefix is not present.</p>
<p><span class="code">BetterListViewAddress</span> structure implements
<span class="code">IComparable</span>, so the two addresses can be compared. Element
that is displayed above other element in Better ListView has always lower
address value. Addresses can also be compared using operators
<span class="code">&lt;</span>, <span class="code">&gt;</span>, <span class="code">&lt;=</span> and
<span class="code">&gt;=</span>.</p>
<h2>Get Item/Group for the Given Address</h2>
<p>There are two methods for retrieving items and groups for the given
address:</p>
<ul>
<li>
<p><span class="code">GetGroupFromAddress(BetterListViewAddress)</span></p>
</li>
<li>
<p><span class="code">GetItemFromAddress(BetterListViewAddress)</span></p>
</li>
</ul>
<h2>Sample Source Code</h2>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">this.listView.BeginUpdate();
this.listView.Columns.Add("Documents", 256);
// create first top-level item
BetterListViewItem itemAudio = new BetterListViewItem("Audio Files");
// add children to the first top-level item
itemAudio.ChildItems.AddRange(
new[]
{
new BetterListViewItem("Call with Josh (2011-10-6).mp3"),
new BetterListViewItem("Great Ringtone.mp3")
});
// create second top-level item
BetterListViewItem itemVideo = new BetterListViewItem("Video Files");
// add children to the second top-level item
itemVideo.ChildItems.AddRange(
new[]
{
new BetterListViewItem("Annual Conference.avi")
});
// add the top-level items to list
// NOTE: children are added automatically
this.listView.Items.AddRange(
new[]
{
itemAudio,
itemVideo
});
this.listView.EndUpdate();</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">' Add any initialization after the InitializeComponent() call.
ListView.BeginUpdate()
ListView.Columns.Add ("Documents", 256)
' create first top-level item
Dim itemAudio As New BetterListViewItem ("Audio Files")
' add children to the first top-level item
itemAudio.ChildItems.AddRange (
New BetterListViewItem() { _
New BetterListViewItem ("Call with Josh (2011-10-6).mp3"),
New BetterListViewItem ("Great Ringtone.mp3")
})
' create second top-level item
Dim itemVideo As New BetterListViewItem ("Video Files")
' add children to the second top-level item
itemVideo.ChildItems.AddRange (
New BetterListViewItem() { _
New BetterListViewItem ("Annual Conference.avi")
})
' add the top-level items to list
' NOTE: children are added automatically
ListView.Items.AddRange (
New BetterListViewItem() { _
itemAudio,
itemVideo
})
ListView.EndUpdate()</code></pre>
<br><div class="banner">
<a href="../../../blog/page/6/index.html"><img src="../resources/overview.gif" alt="Better ListView" class="ss"></a>
<div class="inside">
<div class="text">Better ListView: Ultimate .NET ListView replacement control for WinForms (C#, VB.NET)</div>
<span class="dbtn-c dbtn-hilight"><span class="dbtn-w"><a href="../../../betterlistview.exe" class="dbtn">Download</a></span></span>
<span class="dbtn-c"><span class="dbtn-w"><a href="../../../blog/page/6/index.html" class="dbtn">More Info</a></span></span>
</div>
</div>
<table class="navigation"><tr>
<td class="navigation-previous"><a href="chapter-insertion-mark.html"><strong>
« Insertion Mark</strong></a></td>
<td class="navigation-index"><a href="../../../better-listview-express/documentation.html"><strong>Index</strong></a></td>
<td class="navigation-next"><a href="chapter-item-reorder.html"><strong>Item Reordering »
</strong></a></td>
</tr></table>
<br><table class="footer"><tr>
<td class="footer-title">Better ListView Express Documentation
</td>
<td class="footer-copyright">
Copyright © <a href="../../../index.html" target="_blank">ComponentOwl.com</a>
</td>
</tr></table>
</div></body>
</html>