Files
componentowl-astro/public/documentation/better-listview/data/chapter-performance.html

304 lines
12 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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>Performance</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-owner-draw.html"><strong>
« Owner Drawing</strong></a></td>
<td class="navigation-index"><a href="../../../quick-start-guide/better-listview/index.html"><strong>Index</strong></a></td>
<td class="navigation-next"><a href="chapter-save-load.html"><strong>Saving and Loading ListView Content »
</strong></a></td>
</tr></table>
<br><h1>Performance</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>
<h2>
<a name="beginupdate-endupdate" id="beginupdate-endupdate"></a>Using BeginUpdate and
EndUpdate</h2>
<p>When doing several operations with Better ListView at a time, these
operations should be enclosed in BeginUpdate and EndUpdate method
calls.</p>
<p>For example:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">listView.BeginUpdate();
for (int i = 0; i &lt; 100; i++)
{
listView.Items.Add(String.Format("Item no. {0}", i));
}
listView.EndUpdate();</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">ListView.BeginUpdate()
For i As Integer = 0 To 99
ListView.Items.Add([String].Format("Item no. {0}", i))
Next
listView.EndUpdate()</code></pre>
<p>Without these methods, Better ListView would refresh itself 100
times and the whole operation would take noticeable time. The same applies
to setting properties or modifying other collections (column headers,
sub-items, child items, groups) so it is still convenient to use
<span class="code">BeginUpdate</span> and <span class="code">EndUpdate</span> when setting multiple
properties:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">BeginUpdate();
listView.Items[0].SubItems[1].Align = TextAlignment.Right;
listView.MultiSelect = true;
listView.CheckBoxes = BetterListViewCheckBoxes.TwoState;
EndUpdate();</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">BeginUpdate()
ListView.Items(0).SubItems(1).Align = TextAlignment.Right
ListView.MultiSelect = True
ListView.CheckBoxes = BetterListViewCheckBoxes.TwoState
EndUpdate()</code></pre>
<p>There can be multiple calls of <span class="code">BeginUpdate</span> and the
control will actually refresh after the same number of
<span class="code">EndUpdate</span> calls are made.</p>
<p>It is also possible to call <span class="code">EndUpdate</span> with boolean
parameter. The call <span class="code">EndUpdate(true)</span> will avoid refreshing the
control, but still move the control out of the updation state.</p>
<p>To check whether the control is in updation state, use the
<span class="code">IsUpdating</span> property:</p>
<p><strong>C#</strong></p>
<pre class="prettyprint"><code class="lang-cs">// intentionally call BeginUpdate twice
BeginUpdate();
BeginUpdate();
// listView.IsUpdating is true
EndUpdate();
// still updating, listView.IsUpdating is true
EndUpdate();
// still updating, listView.IsUpdating is false</code></pre>
<p><strong>Visual Basic</strong></p>
<pre class="prettyprint"><code class="lang-vb">' intentionally call BeginUpdate twice
BeginUpdate()
BeginUpdate()
' listView.IsUpdating is true
EndUpdate()
' still updating, listView.IsUpdating is true
EndUpdate()
' still updating, listView.IsUpdating is false</code></pre>
<h2>Performance of Image versus ImageList</h2>
<p>There are two ways of setting images to Better ListView elements:
<span class="code">Image</span> property and <span class="code">ImageList</span> property.</p>
<p><span class="code">ImageList</span> is convenient when you want to use images
which are not attached directly to elements (the element - e.g. item -
only refers to image index or key within the global image list). The
performance of <span class="code">ImageList</span>, however, is quite slow. The
slowness can be painful in some critical cases, like column
resizing.</p>
<p>When working with many items, we recommend using <span class="code">Image</span>
property instead.</p>
<h2>Performance Properties</h2>
<p>Better ListView was designed to be responsive to user although it is
quite complex control. It is sometimes convenient to adjust optimization
settings. This can be done through the following properties:</p>
<ul style="list-style:none">
<li>
<span class="code">BetterListView.AutoSizeItemsInDetailsView</span><ul style="list-style:none"><li>
<p><span class="code">false</span> by default</p>
</li></ul>
</li>
<li>
<span class="code">BetterListView.CacheImages</span><ul style="list-style:none"><li>
<p><span class="code">true</span> by default</p>
</li></ul>
</li>
<li>
<span class="code">BetterListView.MaximumToolTipTextLength</span><ul style="list-style:none"><li>
<p><span class="code">1000</span> by default</p>
</li></ul>
</li>
<li>
<span class="code">BetterListView.OptimizedInvalidation</span><ul style="list-style:none"><li>
<p><span class="code">true</span> by default</p>
</li></ul>
</li>
<li>
<span class="code">BetterListViewColumnHeader.SmoothColumnResize</span><ul style="list-style:none"><li>
<p><span class="code">true</span> by default. Can be set on each column header
separately.</p>
</li></ul>
</li>
<li>
<span class="code">BetterListView.SortOnCollectionChange</span><ul style="list-style:none"><li>
<p><span class="code">true</span> by default</p>
</li></ul>
</li>
</ul>
<h2>Automatic Resizing of Items in Details View</h2>
<p>Better ListView supports displaying items in
<strong><em>Details</em></strong> view even when there are no columns. When
columns are displayed, item width is determined by the total width of all
columns. When columns are not present, items have fixed width by default.
By settings <span class="code">AutoSizeItemsInDetailsView</span> property to
<span class="code">true</span>, items will be always stretched to client area width.
The following images shows item size without and with automatic
resizing:</p>
<p class="images"><img src="performance-autosizeitemsindetailsview1.png"></p>
<p class="images"><img src="performance-autosizeitemsindetailsview2.png"></p>
<p>Items are not resized by default, because it slows performance when
Better ListView contains huge number of items.</p>
<h2>Image Caching</h2>
<p>When Better ListView contains images of various sizes which are
possibly downscaled, its performance can drop. Showing image frames and
shadows can slow down redrawing of the control even more. When
<span class="code">CacheImages</span> property is set to <span class="code">true</span>, Better
ListView downscales every image just once and then stores the scaled image
(also with its frame) to internal cache. The scaled image is then
displayed quickly.</p>
<p>The cache is cleared whenever an item property si changed affecting
image or its border.</p>
<h2>Optimized Invalidation</h2>
<p>When user moves mouse cursor over the control, not all the elements
have to be redrawn. For example, when user moves mouse cursor from column
header A to item B, hot state of these elements changes and only these two
elements are be redrawn. Optimized invalidation finds always the smallest
region to redraw.</p>
<p>This behavior is used when <span class="code">OptimizedInvalidation</span>
property is set to <span class="code">true</span>. This behavior can be sometimes
unwanted, e.g. on some specific <strong><em><a href="chapter-owner-draw.html">Owner drawing</a></em></strong>.</p>
<h2>Smooth Column Resizing</h2>
<p>When columns are resized in <strong><em>Details</em></strong> view, the
items and sub-items are resized as well. Item resizing may pose a
performance bottleneck, when there are huge number of items present and
column resizing animation may not be smooth. It is possible to set
<span class="code">BetterListViewColumnHeader.SmoothColumnResize</span> property to
<span class="code">false</span>, which will cause items and sub-items in the specific
column to be resized only once: when column resizing is finished (e.g.
when user releases mouse button).</p>
<p>When the smooth column resizing feature is turned off, a line is
displayed that shows new column width:</p>
<p class="images"><img src="performance-smoothcolumnresize.png"></p>
<h2>Sorting on Collection Change</h2>
<p>When the Better ListView is sorted and its content is changed, it
keeps sort order by default. This needs, however, to re-sort all the items
whenever there is some change.</p>
<p>This behavior can be turned off by settings
<span class="code">SortOnCollectionChanged</span> property to <span class="code">false</span>. In
that case, Better ListView does not guarantee that the Items collection is
always sorted and you have to perform sorting manually, when
needed.</p>
<h2>Maximum ToolTip Text Length</h2>
<p>The property <span class="code">MaximumToolTipTextLength</span> limits the
maximum allowed length of text within automatic tooltips. When element
text is very long, it may take a long time for a tooltip to
display.</p>
<p>When the element text is too long, it is shortened to length of
(<span class="code">MaximumToolTipTextLength - 1</span>) and an ellipsis character is
added at the end of the text.</p>
<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-owner-draw.html"><strong>
« Owner Drawing</strong></a></td>
<td class="navigation-index"><a href="../../../quick-start-guide/better-listview/index.html"><strong>Index</strong></a></td>
<td class="navigation-next"><a href="chapter-save-load.html"><strong>Saving and Loading ListView Content »
</strong></a></td>
</tr></table>
<br><table class="footer"><tr>
<td class="footer-title">Better ListView Documentation
</td>
<td class="footer-copyright">
Copyright © 2010-2012  <a href="../../../index.html" target="_blank">ComponentOwl.com</a>
</td>
</tr></table>
</div></body>
</html>