361 lines
14 KiB
HTML
361 lines
14 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>Insertion Mark</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-hit-test.html"><strong>
|
|||
|
|
« Hit Test</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-item-hierarchy.html"><strong>Item Hierarchy »
|
|||
|
|
</strong></a></td>
|
|||
|
|
</tr></table>
|
|||
|
|
<br><h1>Insertion Mark</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>Insertion mark is a line showing location between items. Better
|
|||
|
|
ListView support displaying the insertion mark on various locations with
|
|||
|
|
support for groups and item hierarchy:</p>
|
|||
|
|
|
|||
|
|
<p class="images"><img src="insertion-mark-hierarchy1.png"><img src="insertion-mark-hierarchy2.png"><img src="insertion-mark-hierarchy3.png"><img src="insertion-mark-vertical.png"></p>
|
|||
|
|
|
|||
|
|
<p>The basic usage of insertion mark is the same as in regular .NET
|
|||
|
|
ListView. Setting <span class="code">InsertionMark</span> property using one of these
|
|||
|
|
constructors will give you the <strong><em>classic</em></strong> insertion
|
|||
|
|
mark:</p>
|
|||
|
|
|
|||
|
|
<ul>
|
|||
|
|
<li>
|
|||
|
|
<p><span class="code">BetterListViewInsertionMark(int index)</span></p>
|
|||
|
|
</li>
|
|||
|
|
<li>
|
|||
|
|
<p><span class="code">BetterListViewInsertionMark(int index, bool
|
|||
|
|
showAfterItem)</span></p>
|
|||
|
|
</li>
|
|||
|
|
<li>
|
|||
|
|
<p><span class="code">BetterListViewInsertionMark(int index, bool showAfterItem,
|
|||
|
|
Color color)</span></p>
|
|||
|
|
</li>
|
|||
|
|
<li>
|
|||
|
|
<p><span class="code">BetterListViewInsertionMark(int index, bool showAfterItem,
|
|||
|
|
Color color, bool enabled)</span></p>
|
|||
|
|
</li>
|
|||
|
|
</ul>
|
|||
|
|
<p>The last constructor has an extra parameter <span class="code">enabled</span> which
|
|||
|
|
adjusts insertion mark color slightly (giving it alpha transparency) to be
|
|||
|
|
displayed in an <strong><em>inactive</em></strong> or
|
|||
|
|
<strong><em>disabled</em></strong> state.</p>
|
|||
|
|
|
|||
|
|
<p>There are also more general constructors for displaying insertion mark
|
|||
|
|
on arbitrary location in item hierarchy and on groups:</p>
|
|||
|
|
|
|||
|
|
<ul>
|
|||
|
|
<li>
|
|||
|
|
<p><span class="code">BetterListViewInsertionMark(BetterListViewInsertionLocation
|
|||
|
|
insertionLocation)</span></p>
|
|||
|
|
</li>
|
|||
|
|
<li>
|
|||
|
|
<p><span class="code">BetterListViewInsertionMark(BetterListViewInsertionLocation
|
|||
|
|
insertionLocation, Color color)</span></p>
|
|||
|
|
</li>
|
|||
|
|
<li>
|
|||
|
|
<p><span class="code">BetterListViewInsertionMark(BetterListViewInsertionLocation
|
|||
|
|
insertionLocation, Color color, bool enabled)</span></p>
|
|||
|
|
</li>
|
|||
|
|
</ul>
|
|||
|
|
<p>Instead of <span class="code">index</span>, there is an
|
|||
|
|
<span class="code">insertionLocation</span> parameter.</p>
|
|||
|
|
|
|||
|
|
<h2>Insertion Locations</h2>
|
|||
|
|
|
|||
|
|
|
|||
|
|
<p>The <span class="code">BetterListViewInsertionLocation</span> type can describe
|
|||
|
|
any location in item hierarchy and on groups. The location consists of
|
|||
|
|
three properties:</p>
|
|||
|
|
|
|||
|
|
<ul style="list-style:none">
|
|||
|
|
<li>Address<ul style="list-style:none"><li>
|
|||
|
|
<p>Counterpart to index in item hierarchy (see <strong><em><a href="chapter-item-hierarchy.html#addressing-elements">Addressing
|
|||
|
|
Elements</a></em></strong>). It can describe either group or a child
|
|||
|
|
item.</p>
|
|||
|
|
</li></ul>
|
|||
|
|
</li>
|
|||
|
|
<li>DropPart<ul style="list-style:none"><li>
|
|||
|
|
<p>Defines relative insertion location to the element specified
|
|||
|
|
by the <span class="code">Address</span>. The drop part value can be either
|
|||
|
|
<span class="code">Before</span> the element, <span class="code">After</span> the element or
|
|||
|
|
<span class="code">Inside</span> the element. For groups, the <span class="code">Inside</span>
|
|||
|
|
is the only valid value. Items can display any of the three drop
|
|||
|
|
parts. The difference between <span class="code">After</span> and
|
|||
|
|
<span class="code">Inside</span> is that with <span class="code">Inside</span> it is possible
|
|||
|
|
to create new child items. Otherwise, the location <strong><em>inside
|
|||
|
|
item</em></strong> can be substituted by <strong><em>before first child
|
|||
|
|
item of that item</em></strong>.</p>
|
|||
|
|
</li></ul>
|
|||
|
|
</li>
|
|||
|
|
<li>Level<ul style="list-style:none"><li>
|
|||
|
|
<p>Specifies target level in item hierarchy. It is valid for
|
|||
|
|
<span class="code">Before</span> and <span class="code">After</span> drop parts only. By
|
|||
|
|
default, the <span class="code">Level</span> property has value of
|
|||
|
|
<span class="code">BetterListViewInsertionLocation.LevelUndefined</span> and thus
|
|||
|
|
inheriting level of the currently located item. When set, it
|
|||
|
|
overrides the level and the insertion mark can start on smaller
|
|||
|
|
offset than the child item. This is used mainly internally for item
|
|||
|
|
reordering, when user puts item after the last child item and then
|
|||
|
|
moves mouse cursor to the left, to put it after its parent,
|
|||
|
|
actually.</p>
|
|||
|
|
</li></ul>
|
|||
|
|
</li>
|
|||
|
|
<li>Offset<ul style="list-style:none"><li>
|
|||
|
|
<p>Specifies custom additional indentation of insertion mark (in
|
|||
|
|
pixels).</p>
|
|||
|
|
</li></ul>
|
|||
|
|
</li>
|
|||
|
|
</ul>
|
|||
|
|
<h2>Sample Source Code</h2>
|
|||
|
|
|
|||
|
|
|
|||
|
|
<p>The following sample shows how to display insertion mark according
|
|||
|
|
to current mouse position (see <strong><em><a href="chapter-hit-test.html">Hit Test</a></em></strong>).</p>
|
|||
|
|
|
|||
|
|
<p><strong>C#</strong></p>
|
|||
|
|
<pre class="prettyprint"><code class="lang-cs">this.listView.BeginUpdate();
|
|||
|
|
|
|||
|
|
// create groups with items and child items
|
|||
|
|
BetterListViewGroup groupRecent = new BetterListViewGroup("Recent Items");
|
|||
|
|
|
|||
|
|
groupRecent.Items.AddRange(
|
|||
|
|
new[]
|
|||
|
|
{
|
|||
|
|
"Ming Dynasty Vase",
|
|||
|
|
"Collection of Rembrandt",
|
|||
|
|
"Photos from Prokudin Gorskij"
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
groupRecent.Items[1].ChildItems.AddRange(
|
|||
|
|
new[]
|
|||
|
|
{
|
|||
|
|
"The Night Watch",
|
|||
|
|
"Belshazzar's Feast"
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
BetterListViewGroup groupArchived = new BetterListViewGroup("Archived Items");
|
|||
|
|
|
|||
|
|
groupArchived.Items.AddRange(
|
|||
|
|
new[]
|
|||
|
|
{
|
|||
|
|
"Statue of Zeus",
|
|||
|
|
"Rare pens from Hamburg and Dresden"
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
this.listView.Groups.AddRange(
|
|||
|
|
new[]
|
|||
|
|
{
|
|||
|
|
groupRecent,
|
|||
|
|
groupArchived
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// set custom color for the insertion mark
|
|||
|
|
this.listView.ColorInsertionMark = Color.DarkGreen;
|
|||
|
|
// make the groups visible
|
|||
|
|
this.listView.ShowGroups = true;
|
|||
|
|
|
|||
|
|
this.listView.EndUpdate();
|
|||
|
|
|
|||
|
|
// this will set insertion mark every time hit test changes
|
|||
|
|
this.listView.HitTestChanged += ListViewHitTestChanged;</code></pre>
|
|||
|
|
|
|||
|
|
<p><strong>Visual Basic</strong></p>
|
|||
|
|
<pre class="prettyprint"><code class="lang-vb">ListView.BeginUpdate()
|
|||
|
|
|
|||
|
|
' create groups with items and child items
|
|||
|
|
Dim groupRecent As New BetterListViewGroup("Recent Items")
|
|||
|
|
|
|||
|
|
groupRecent.Items.AddRange(
|
|||
|
|
New String() {
|
|||
|
|
"Ming Dynasty Vase",
|
|||
|
|
"Collection of Rembrandt",
|
|||
|
|
"Photos from Prokudin Gorskij"
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
groupRecent.Items(1).ChildItems.AddRange(
|
|||
|
|
New String() {
|
|||
|
|
"The Night Watch",
|
|||
|
|
"Belshazzar's Feast"
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
Dim groupArchived As New BetterListViewGroup("Archived Items")
|
|||
|
|
|
|||
|
|
groupArchived.Items.AddRange(
|
|||
|
|
New String() {
|
|||
|
|
"Statue of Zeus",
|
|||
|
|
"Rare pens from Hamburg and Dresden"
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
ListView.Groups.AddRange(New BetterListViewGroup() {groupRecent, groupArchived})
|
|||
|
|
|
|||
|
|
' set custom color for the insertion mark
|
|||
|
|
ListView.ColorInsertionMark = Color.DarkGreen
|
|||
|
|
' make the groups visible
|
|||
|
|
ListView.ShowGroups = True
|
|||
|
|
|
|||
|
|
ListView.EndUpdate()
|
|||
|
|
|
|||
|
|
' this will set insertion mark every time hit test changes
|
|||
|
|
AddHandler ListView.HitTestChanged, AddressOf ListViewHitTestChanged</code></pre>
|
|||
|
|
|
|||
|
|
<p>The <span class="code">HitTestInfoChanged</span> event handler determines the
|
|||
|
|
actual insertion mark location and sets it:</p>
|
|||
|
|
|
|||
|
|
<p><strong>C#</strong></p>
|
|||
|
|
<pre class="prettyprint"><code class="lang-cs">void ListViewHitTestChanged(object sender, BetterListViewHitTestChangedEventArgs eventArgs)
|
|||
|
|
{
|
|||
|
|
// get current hit test information
|
|||
|
|
BetterListViewHitTestInfo hitTestInfo = eventArgs.HitTestInfoNew;
|
|||
|
|
|
|||
|
|
// get address and drop part to assembly an insertion mark location
|
|||
|
|
BetterListViewAddress address;
|
|||
|
|
BetterListViewDropPart dropPart;
|
|||
|
|
|
|||
|
|
if (hitTestInfo.Item != null)
|
|||
|
|
{
|
|||
|
|
// the mouse cursor is located on item
|
|||
|
|
address = hitTestInfo.Item.Address;
|
|||
|
|
|
|||
|
|
if ((hitTestInfo.ItemPart & BetterListViewHitPart.VCenter) == BetterListViewHitPart.VCenter)
|
|||
|
|
{
|
|||
|
|
// the mouse cursor is located in the centre of the item - the insertion mark will point inside the item
|
|||
|
|
dropPart = BetterListViewDropPart.Inside;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
// the mouse cursor is located on other parts of the item - the insertion mark will point before on after the item
|
|||
|
|
dropPart = (((hitTestInfo.ItemPart & BetterListViewHitPart.Bottom) == BetterListViewHitPart.Bottom)
|
|||
|
|
? BetterListViewDropPart.After
|
|||
|
|
: BetterListViewDropPart.Before);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (
|
|||
|
|
hitTestInfo.Group != null)
|
|||
|
|
{
|
|||
|
|
// the mouse cursor is located on group
|
|||
|
|
address = hitTestInfo.Group.Address;
|
|||
|
|
dropPart = BetterListViewDropPart.Inside; //NOTE: only Inside is allowed as drop part on groups
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
// the mouse cursor is not located on item nor group
|
|||
|
|
address = null;
|
|||
|
|
dropPart = BetterListViewDropPart.Undefined;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (address != null)
|
|||
|
|
{
|
|||
|
|
// set insertion mark on the constructed location
|
|||
|
|
this.listView.InsertionMark = new BetterListViewInsertionMark(new BetterListViewInsertionLocation(address, dropPart));
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
// reset insertion mark
|
|||
|
|
this.listView.InsertionMark = BetterListViewInsertionMark.Empty;
|
|||
|
|
}
|
|||
|
|
}</code></pre>
|
|||
|
|
|
|||
|
|
<p><strong>Visual Basic</strong></p>
|
|||
|
|
<pre class="prettyprint"><code class="lang-vb">Sub ListViewHitTestChanged(ByVal sender As Object, ByVal eventArgs As BetterListViewHitTestChangedEventArgs)
|
|||
|
|
|
|||
|
|
' get current hit test information
|
|||
|
|
Dim hitTestInfo As BetterListViewHitTestInfo = eventArgs.HitTestInfoNew
|
|||
|
|
|
|||
|
|
' get address and drop part to assembly an insertion mark location
|
|||
|
|
Dim address As BetterListViewAddress
|
|||
|
|
Dim dropPart As BetterListViewDropPart
|
|||
|
|
|
|||
|
|
If hitTestInfo.Item IsNot Nothing Then
|
|||
|
|
|
|||
|
|
' the mouse cursor is located on item
|
|||
|
|
address = hitTestInfo.Item.Address
|
|||
|
|
|
|||
|
|
If (hitTestInfo.ItemPart And BetterListViewHitPart.VCenter) = BetterListViewHitPart.VCenter Then
|
|||
|
|
|
|||
|
|
' the mouse cursor is located in the centre of the item - the insertion mark will point inside the item
|
|||
|
|
dropPart = BetterListViewDropPart.Inside
|
|||
|
|
|
|||
|
|
Else
|
|||
|
|
|
|||
|
|
' the mouse cursor is located on other parts of the item - the insertion mark will point before on after the item
|
|||
|
|
dropPart = (If(((hitTestInfo.ItemPart And BetterListViewHitPart.Bottom) = BetterListViewHitPart.Bottom), BetterListViewDropPart.After, BetterListViewDropPart.Before))
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
ElseIf hitTestInfo.Group IsNot Nothing Then
|
|||
|
|
|
|||
|
|
' the mouse cursor is located on group
|
|||
|
|
address = hitTestInfo.Group.Address
|
|||
|
|
'NOTE: only Inside is allowed as drop part on groups
|
|||
|
|
dropPart = BetterListViewDropPart.Inside
|
|||
|
|
|
|||
|
|
Else
|
|||
|
|
|
|||
|
|
' the mouse cursor is not located on item nor group
|
|||
|
|
address = Nothing
|
|||
|
|
dropPart = BetterListViewDropPart.Undefined
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
If address IsNot Nothing Then
|
|||
|
|
|
|||
|
|
' set insertion mark on the constructed location
|
|||
|
|
ListView.InsertionMark = New BetterListViewInsertionMark(New BetterListViewInsertionLocation(address, dropPart))
|
|||
|
|
|
|||
|
|
Else
|
|||
|
|
|
|||
|
|
' reset insertion mark
|
|||
|
|
ListView.InsertionMark = BetterListViewInsertionMark.Empty
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
End Sub</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-hit-test.html"><strong>
|
|||
|
|
« Hit Test</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-item-hierarchy.html"><strong>Item Hierarchy »
|
|||
|
|
</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>
|