-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
ListViewInsertionMark.xml
342 lines (282 loc) · 27.7 KB
/
ListViewInsertionMark.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<Type Name="ListViewInsertionMark" FullName="System.Windows.Forms.ListViewInsertionMark">
<TypeSignature Language="C#" Value="public sealed class ListViewInsertionMark" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit ListViewInsertionMark extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Windows.Forms.ListViewInsertionMark" />
<TypeSignature Language="VB.NET" Value="Public NotInheritable Class ListViewInsertionMark" />
<TypeSignature Language="F#" Value="type ListViewInsertionMark = class" />
<TypeSignature Language="C++ CLI" Value="public ref class ListViewInsertionMark sealed" />
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="windowsdesktop-8.0;windowsdesktop-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="windowsdesktop-8.0;windowsdesktop-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(1)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Used to indicate the expected drop location when an item is dragged to a new position in a <see cref="T:System.Windows.Forms.ListView" /> control. This functionality is available only on Windows XP and later.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can retrieve a <xref:System.Windows.Forms.ListViewInsertionMark> from the <xref:System.Windows.Forms.ListView.InsertionMark%2A> property of a <xref:System.Windows.Forms.ListView> control and use it to visually indicate the expected drop location in a drag-and-drop operation when an item is dragged to a new position.
This feature works only when the <xref:System.Windows.Forms.ListView.AutoArrange%2A?displayProperty=nameWithType> property is set to `true` and when the <xref:System.Windows.Forms.ListView> control does not sort the items automatically. To prevent automatic sorting, the <xref:System.Windows.Forms.ListView.Sorting%2A?displayProperty=nameWithType> property must be set to <xref:System.Windows.Forms.SortOrder.None?displayProperty=nameWithType> and the <xref:System.Windows.Forms.ListView.View%2A?displayProperty=nameWithType> property must be set to <xref:System.Windows.Forms.View.LargeIcon?displayProperty=nameWithType>, <xref:System.Windows.Forms.View.SmallIcon?displayProperty=nameWithType>, or <xref:System.Windows.Forms.View.Tile?displayProperty=nameWithType>. Additionally, the insertion mark feature cannot be used with the <xref:System.Windows.Forms.ListView> grouping feature because the grouping feature orders the items by group membership.
The <xref:System.Windows.Forms.ListViewInsertionMark> class is typically used in a handler for the <xref:System.Windows.Forms.Control.DragOver?displayProperty=nameWithType> or <xref:System.Windows.Forms.Control.MouseMove?displayProperty=nameWithType> event to update the position of the insertion mark as an item is dragged. It is also used in a handler for the <xref:System.Windows.Forms.Control.DragDrop?displayProperty=nameWithType> or <xref:System.Windows.Forms.Control.MouseUp?displayProperty=nameWithType> event to insert a dragged item at the correct location.
To update the position of the insertion mark, follow these steps:
1. In a handler for the <xref:System.Windows.Forms.Control.DragOver?displayProperty=nameWithType> or <xref:System.Windows.Forms.Control.MouseMove?displayProperty=nameWithType> event, use the <xref:System.Windows.Forms.ListView.InsertionMark%2A?displayProperty=nameWithType> property to access the <xref:System.Windows.Forms.ListViewInsertionMark> object associated with the <xref:System.Windows.Forms.ListView> control.
2. Use the <xref:System.Windows.Forms.ListViewInsertionMark.NearestIndex%2A> method to retrieve the index of the item closest to the mouse pointer.
3. Pass the index value to the <xref:System.Windows.Forms.ListView.GetItemRect%2A?displayProperty=nameWithType> method to retrieve the bounding rectangle of the item.
4. If the mouse pointer is located to the left of the midpoint of the bounding rectangle, set the <xref:System.Windows.Forms.ListViewInsertionMark.AppearsAfterItem%2A> property to `false`; otherwise, set it to `true`.
5. Set the <xref:System.Windows.Forms.ListViewInsertionMark.Index%2A> property to the index value retrieved from the <xref:System.Windows.Forms.ListViewInsertionMark.NearestIndex%2A> method. The insertion mark appears next to item with the specified index, either to the left or the right, depending on the <xref:System.Windows.Forms.ListViewInsertionMark.AppearsAfterItem%2A> property value. If an item is dragged over itself, the index is -1 and the insertion mark is hidden.
To insert the dragged item at the correct location, follow these steps:
1. In a handler for the <xref:System.Windows.Forms.Control.DragDrop?displayProperty=nameWithType> or <xref:System.Windows.Forms.Control.MouseUp?displayProperty=nameWithType> event, use the <xref:System.Windows.Forms.ListViewInsertionMark.Index%2A> property to determine the current location of the insertion mark. Store this value to be used later as the insertion index.
2. If the <xref:System.Windows.Forms.ListViewInsertionMark.AppearsAfterItem%2A> property is set to `true`, increment the stored insertion index value.
3. Use the <xref:System.Windows.Forms.ListView.ListViewItemCollection.Insert%2A?displayProperty=nameWithType> method to insert a clone of the dragged item into the <xref:System.Windows.Forms.ListView.Items%2A?displayProperty=nameWithType> collection at the stored insertion index.
4. Use the <xref:System.Windows.Forms.ListView.ListViewItemCollection.Remove%2A?displayProperty=nameWithType> method to remove the original copy of the dragged item.
You must insert a clone of the dragged item before the original copy is removed so the index values in the <xref:System.Windows.Forms.ListView.Items%2A?displayProperty=nameWithType> collection are not altered before the insertion.
To ensure that the items are displayed in the same order as their index values, you must set the <xref:System.Windows.Forms.ListView.ListViewItemSorter%2A?displayProperty=nameWithType> property to an implementation of the <xref:System.Collections.IComparer> interface that sorts items by index value. For more information, see the Example section.
You can modify the color of the insertion mark by using the <xref:System.Windows.Forms.ListViewInsertionMark.Color%2A> property. If you need the size or position of the insertion mark, you can get its bounding rectangle through the <xref:System.Windows.Forms.ListViewInsertionMark.Bounds%2A> property.
> [!NOTE]
> The insertion mark feature is available only on Windows XP and the Windows Server 2003 family when your application calls the <xref:System.Windows.Forms.Application.EnableVisualStyles%2A?displayProperty=nameWithType> method. On earlier operating systems, any code relating to the insertion mark will be ignored and the insertion mark will not appear. As a result, any code that depends on the insertion mark feature may not work correctly. You may want to include a test that determines whether the insertion mark feature is available, and provide alternate functionality when it is unavailable. For example, you may want to bypass all code that implements drag-and-drop item repositioning when running on operating systems that do not support insertion marks.
>
> The insertion mark feature is provided by the same library that provides the operating system themes feature. To check for the availability of this library, call the <xref:System.Windows.Forms.FeatureSupport.IsPresent%28System.Object%29?displayProperty=nameWithType> method overload and pass in the <xref:System.Windows.Forms.OSFeature.Themes?displayProperty=nameWithType> value.
## Examples
The following code example demonstrates how to use the <xref:System.Windows.Forms.ListView> insertion mark feature and implements drag-and-drop item reordering using the standard drag events. The position of the insertion mark is updated in a handler for the <xref:System.Windows.Forms.Control.DragOver?displayProperty=nameWithType> event. In this handler, the position of the mouse pointer is compared to the midpoint of the nearest item, and the result is used to determine whether the insertion mark appears to the left or the right of the item.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/CPP/listviewinsertionmarkexample.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/ListView/InsertionMark/listviewinsertionmarkexample.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/VB/listviewinsertionmarkexample.vb" id="Snippet1":::
]]></format>
</remarks>
<altmember cref="T:System.Windows.Forms.ListView" />
</Docs>
<Members>
<Member MemberName="AppearsAfterItem">
<MemberSignature Language="C#" Value="public bool AppearsAfterItem { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool AppearsAfterItem" />
<MemberSignature Language="DocId" Value="P:System.Windows.Forms.ListViewInsertionMark.AppearsAfterItem" />
<MemberSignature Language="VB.NET" Value="Public Property AppearsAfterItem As Boolean" />
<MemberSignature Language="F#" Value="member this.AppearsAfterItem : bool with get, set" Usage="System.Windows.Forms.ListViewInsertionMark.AppearsAfterItem" />
<MemberSignature Language="C++ CLI" Value="public:
 property bool AppearsAfterItem { bool get(); void set(bool value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets a value indicating whether the insertion mark appears to the right of the item with the index specified by the <see cref="P:System.Windows.Forms.ListViewInsertionMark.Index" /> property.</summary>
<value>
<see langword="true" /> if the insertion mark appears to the right of the item with the index specified by the <see cref="P:System.Windows.Forms.ListViewInsertionMark.Index" /> property; otherwise, <see langword="false" />. The default is <see langword="false" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Windows.Forms.ListViewInsertionMark.NearestIndex%2A> method lets you find the item closest to the mouse pointer, but you must do your own calculations to determine whether the insertion mark should appear before or after this item.
To calculate the value needed for the <xref:System.Windows.Forms.ListViewInsertionMark.AppearsAfterItem%2A> property, follow these steps:
1. Use the <xref:System.Windows.Forms.ListViewInsertionMark.NearestIndex%2A> method to retrieve the index of the item closest to the mouse pointer.
2. Pass the index value to the <xref:System.Windows.Forms.ListView.GetItemRect%2A?displayProperty=nameWithType> method to retrieve the bounding rectangle of the item.
3. If the mouse pointer is located to the left of the midpoint of the bounding rectangle, set the <xref:System.Windows.Forms.ListViewInsertionMark.AppearsAfterItem%2A> property to `false`; otherwise, set it to `true`.
For more information, see the <xref:System.Windows.Forms.ListViewInsertionMark> overview reference topic.
## Examples
The following code example demonstrates how to use the <xref:System.Windows.Forms.ListView> insertion mark feature and implements drag-and-drop item reordering using the standard drag events. The position of the insertion mark is updated in a handler for the <xref:System.Windows.Forms.Control.DragOver?displayProperty=nameWithType> event. In this handler, the position of the mouse pointer is compared to the midpoint of the nearest item, and the result is used to determine whether the insertion mark appears to the left or the right of the item.
For the complete example, see the <xref:System.Windows.Forms.ListViewInsertionMark> overview reference topic.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/CPP/listviewinsertionmarkexample.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/ListView/InsertionMark/listviewinsertionmarkexample.cs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/VB/listviewinsertionmarkexample.vb" id="Snippet3":::
]]></format>
</remarks>
<altmember cref="T:System.Windows.Forms.ListView" />
</Docs>
</Member>
<Member MemberName="Bounds">
<MemberSignature Language="C#" Value="public System.Drawing.Rectangle Bounds { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Drawing.Rectangle Bounds" />
<MemberSignature Language="DocId" Value="P:System.Windows.Forms.ListViewInsertionMark.Bounds" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Bounds As Rectangle" />
<MemberSignature Language="F#" Value="member this.Bounds : System.Drawing.Rectangle" Usage="System.Windows.Forms.ListViewInsertionMark.Bounds" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::Drawing::Rectangle Bounds { System::Drawing::Rectangle get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Drawing.Rectangle</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the bounding rectangle of the insertion mark.</summary>
<value>A <see cref="T:System.Drawing.Rectangle" /> that represents the position and size of the insertion mark.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The coordinates in the insertion mark bounding rectangle are relative to the upper-left corner of the <xref:System.Windows.Forms.ListView> control.
]]></format>
</remarks>
<altmember cref="T:System.Windows.Forms.ListView" />
</Docs>
</Member>
<Member MemberName="Color">
<MemberSignature Language="C#" Value="public System.Drawing.Color Color { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Drawing.Color Color" />
<MemberSignature Language="DocId" Value="P:System.Windows.Forms.ListViewInsertionMark.Color" />
<MemberSignature Language="VB.NET" Value="Public Property Color As Color" />
<MemberSignature Language="F#" Value="member this.Color : System.Drawing.Color with get, set" Usage="System.Windows.Forms.ListViewInsertionMark.Color" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::Drawing::Color Color { System::Drawing::Color get(); void set(System::Drawing::Color value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Drawing.Color</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the color of the insertion mark.</summary>
<value>A <see cref="T:System.Drawing.Color" /> value that represents the color of the insertion mark. The default value is the value of the <see cref="P:System.Windows.Forms.ListView.ForeColor" /> property.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use this property to set the insertion mark color to a value other than the foreground color of the <xref:System.Windows.Forms.ListView> control.
## Examples
The following code example demonstrates how to use the <xref:System.Windows.Forms.ListView> insertion mark feature and implements drag-and-drop item reordering using the standard drag events. The position of the insertion mark is updated in a handler for the <xref:System.Windows.Forms.Control.DragOver?displayProperty=nameWithType> event. In this handler, the position of the mouse pointer is compared to the midpoint of the nearest item, and the result is used to determine whether the insertion mark appears to the left or the right of the item.
For the complete example, see the <xref:System.Windows.Forms.ListViewInsertionMark> overview reference topic.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/CPP/listviewinsertionmarkexample.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/ListView/InsertionMark/listviewinsertionmarkexample.cs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/VB/listviewinsertionmarkexample.vb" id="Snippet2":::
]]></format>
</remarks>
<altmember cref="T:System.Windows.Forms.ListView" />
</Docs>
</Member>
<Member MemberName="Index">
<MemberSignature Language="C#" Value="public int Index { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance int32 Index" />
<MemberSignature Language="DocId" Value="P:System.Windows.Forms.ListViewInsertionMark.Index" />
<MemberSignature Language="VB.NET" Value="Public Property Index As Integer" />
<MemberSignature Language="F#" Value="member this.Index : int with get, set" Usage="System.Windows.Forms.ListViewInsertionMark.Index" />
<MemberSignature Language="C++ CLI" Value="public:
 property int Index { int get(); void set(int value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the index of the item next to which the insertion mark appears.</summary>
<value>The index of the item next to which the insertion mark appears or -1 when the insertion mark is hidden.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The insertion mark appears to the left of the item with the specified index if the <xref:System.Windows.Forms.ListViewInsertionMark.AppearsAfterItem%2A> property is set to `false`; otherwise, it appears to the right of the item. The insertion mark disappears automatically when a dragged item is inserted into the <xref:System.Windows.Forms.ListView.Items%2A?displayProperty=nameWithType> collection. To remove the insertion mark manually, for example, when an item is dragged onto itself or dragged outside the control, set the <xref:System.Windows.Forms.ListViewInsertionMark.Index%2A> value to -1.
Use the <xref:System.Windows.Forms.ListViewInsertionMark.NearestIndex%2A> method to retrieve the index of the item closest to a specified location, such as the location of the mouse pointer when positioning an item in a drag-and-drop operation.
## Examples
The following code example demonstrates how to use the <xref:System.Windows.Forms.ListView> insertion mark feature and implements drag-and-drop item reordering using the standard drag events. The position of the insertion mark is updated in a handler for the <xref:System.Windows.Forms.Control.DragOver?displayProperty=nameWithType> event. In this handler, the position of the mouse pointer is compared to the midpoint of the nearest item, and the result is used to determine whether the insertion mark appears to the left or the right of the item.
For the complete example, see the <xref:System.Windows.Forms.ListViewInsertionMark> overview reference topic.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/CPP/listviewinsertionmarkexample.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/ListView/InsertionMark/listviewinsertionmarkexample.cs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/VB/listviewinsertionmarkexample.vb" id="Snippet3":::
]]></format>
</remarks>
<altmember cref="T:System.Windows.Forms.ListView" />
</Docs>
</Member>
<Member MemberName="NearestIndex">
<MemberSignature Language="C#" Value="public int NearestIndex (System.Drawing.Point pt);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance int32 NearestIndex(valuetype System.Drawing.Point pt) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Forms.ListViewInsertionMark.NearestIndex(System.Drawing.Point)" />
<MemberSignature Language="VB.NET" Value="Public Function NearestIndex (pt As Point) As Integer" />
<MemberSignature Language="F#" Value="member this.NearestIndex : System.Drawing.Point -> int" Usage="listViewInsertionMark.NearestIndex pt" />
<MemberSignature Language="C++ CLI" Value="public:
 int NearestIndex(System::Drawing::Point pt);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="pt" Type="System.Drawing.Point" />
</Parameters>
<Docs>
<param name="pt">A <see cref="T:System.Drawing.Point" /> representing the location from which to find the nearest item.</param>
<summary>Retrieves the index of the item closest to the specified point.</summary>
<returns>The index of the item closest to the specified point or -1 if the closest item is the item currently being dragged.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method lets you locate the item closest to the mouse pointer when doing a drag-and-drop operation. Use the index value returned to set the <xref:System.Windows.Forms.ListViewInsertionMark.Index%2A> property. When the item closest to the mouse pointer is the item being dragged, the return value of this method is -1. In this case, setting the <xref:System.Windows.Forms.ListViewInsertionMark.Index%2A> property to this value hides the insertion mark.
This method finds the closest item regardless of where the mouse pointer is located, while the <xref:System.Windows.Forms.ListView.GetItemAt%2A?displayProperty=nameWithType> method returns the item at the specified location only, or `null` if there is no item at that location. The <xref:System.Windows.Forms.ListView.GetItemAt%2A?displayProperty=nameWithType> method returns `null`, for example, when the mouse pointer is located between two items. For this reason, you should always use the <xref:System.Windows.Forms.ListViewInsertionMark.NearestIndex%2A> method when using a drag-and-drop operation to position items.
## Examples
The following code example demonstrates how to use the <xref:System.Windows.Forms.ListView> insertion mark feature and implements drag-and-drop item reordering using the standard drag events. The position of the insertion mark is updated in a handler for the <xref:System.Windows.Forms.Control.DragOver?displayProperty=nameWithType> event. In this handler, the position of the mouse pointer is compared to the midpoint of the nearest item, and the result is used to determine whether the insertion mark appears to the left or the right of the item.
For the complete example, see the <xref:System.Windows.Forms.ListViewInsertionMark> overview reference topic.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/CPP/listviewinsertionmarkexample.cpp" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/ListView/InsertionMark/listviewinsertionmarkexample.cs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.ListView.InsertionMark/VB/listviewinsertionmarkexample.vb" id="Snippet3":::
]]></format>
</remarks>
<altmember cref="T:System.Windows.Forms.ListView" />
</Docs>
</Member>
</Members>
</Type>