Files

161 lines
6.8 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>Collections</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-checkboxes.html"><strong>
« Check Boxes</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-columns.html"><strong>Columns »
</strong></a></td>
</tr></table>
<br><h1>Collections</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>
<p>Better ListView contains several types collections of its elements
(columns, items, sub-items, groups). These can be accessed via
properties:</p>
<ul>
<li>
<p><span class="code">Columns</span></p>
</li>
<li>
<p><span class="code">Items</span></p>
</li>
<li>
<p><span class="code">Groups</span></p>
</li>
<li>
<p><span class="code">BetterListViewItem.SubItems</span></p>
</li>
<li>
<p><span class="code">BetterListViewItem.ChildItems</span></p>
</li>
</ul>
<br><hr>
<p class="note"><strong><em>Better ListView Express</em></strong> does not contain the
<span class="code">BetterListViewItem.ChildItems</span> collection as it does not
support hierarchical items.</p>
<hr>
<br><p>Each of these collections are of type
<span class="code">BetterListViewElementCollection&lt;TItem&gt;</span> where
<span class="code">TItem</span> is collection element type. All these collection also
implement <span class="code">IList&lt;TItem&gt;</span>,
<span class="code">ICollection&lt;TItem&gt;</span> and their nongeneric
companions.</p>
<p>They also implement extra functionality through
<span class="code">IExtendedList&lt;TItem&gt;</span>:</p>
<ul style="list-style:none">
<li>
<span class="code">AddRange</span><ul style="list-style:none"><li>
<p>add set of items</p>
</li></ul>
</li>
<li>
<span class="code">RemoveRange</span><ul style="list-style:none"><li>
<p>remove subset of items</p>
</li></ul>
</li>
</ul>
<p>These collections are bound to Better ListView, so any modification to
these collection will be projected into control state.</p>
<p>When the collection is created by user code, e.g.:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">var myItems = new BetterListViewItemCollection();</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">Dim myItems = New BetterListViewItemCollection()</code></pre>
<p>then the collection is not bound to the control and its state is
independent on the control's state.</p>
<p>All the collections are both binary and XML serializable.</p>
<h2>Adding Elements</h2>
<p>Specific collections provide several overrides for easy addition of
items, for example:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">myItems.Add("New Item");</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">myItems.Add("New Item")</code></pre>
<p>Adds new item with text 'New Item' in the collection.</p>
<p>All Better ListView collections support adding arbitrary objects,
for example:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">var person = new Person("Mark Bradley", 13, Gender.Male);
myItems.Add(person);</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">Dim person = New Person("Mark Bradley", 13, Gender.Male)
myItems.Add(person)</code></pre>
<p>This will create a new BetterListViewItem with Text property
obtained from converting the <span class="code">Person</span> object. The type can
either provide custom <span class="code">TypeConverter</span>, or default
<span class="code">TypeConverter</span> (for primive types) or <span class="code">ToString</span>
method is used for conversion.</p>
<p>Multiple custom items can be added either:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">myItems.AddRange(new object[] { person1, person2, "New Person" });</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">myItems.AddRange(New Object() {person1, person2, "New Person"})</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-checkboxes.html"><strong>
« Check Boxes</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-columns.html"><strong>Columns »
</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>