ListViewInsertionMark.Index プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As ListViewInsertionMark Dim value As Integer value = instance.Index instance.Index = value
挿入マークが表示される位置の横にある項目のインデックス。挿入マークが非表示の時には、-1 が返されます。

AppearsAfterItem プロパティが false の場合、指定されたインデックスを持つ項目の左側に挿入マークが表示されます。それ以外の場合、項目の右側に挿入マークが表示されます。ドラッグしている項目が ListView.Items コレクションに挿入されると、挿入マークは自動的に消えます。たとえば項目をその項目自体の上にドラッグした場合や、コントロールの外にドラッグした場合に、挿入マークを手動で削除するには、Index 値を -1 に設定します。
ドラッグ アンド ドロップ操作で項目を移動するときに、マウス ポインタの位置など、指定した位置に最も近い項目のインデックスを取得するには、NearestIndex メソッドを使用します。

ListView の挿入マーク機能を使用し、標準のドラッグ イベントを使ったドラッグ アンド ドロップ項目の並べ替えを実装する方法を次のコード例に示します。挿入マークの位置は、Control.DragOver イベントのハンドラで更新されます。このハンドラでは、マウス ポインタの位置を、最も近くにある項目の中心と比較し、その結果を使用して、挿入マークを項目の右に表示するか、左に表示するかを決定しています。
コード全体については、ListViewInsertionMark の概要のリファレンス トピックを参照してください。
' Moves the insertion mark as the item is dragged. Private Sub myListView_DragOver(sender As Object, e As DragEventArgs) ' Retrieve the client coordinates of the mouse pointer. Dim targetPoint As Point = myListView.PointToClient(New Point(e.X, e.Y)) ' Retrieve the index of the item closest to the mouse pointer. Dim targetIndex As Integer = _ myListView.InsertionMark.NearestIndex(targetPoint) ' Confirm that the mouse pointer is not over the dragged item. If targetIndex > -1 Then ' Determine whether the mouse pointer is to the left or ' the right of the midpoint of the closest item and set ' the InsertionMark.AppearsAfterItem property accordingly. Dim itemBounds As Rectangle = myListView.GetItemRect(targetIndex) If targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) Then myListView.InsertionMark.AppearsAfterItem = True Else myListView.InsertionMark.AppearsAfterItem = False End If End If ' Set the location of the insertion mark. If the mouse is ' over the dragged item, the targetIndex value is -1 and ' the insertion mark disappears. myListView.InsertionMark.Index = targetIndex End Sub 'myListView_DragOver
// Moves the insertion mark as the item is dragged. private void myListView_DragOver(object sender, DragEventArgs e) { // Retrieve the client coordinates of the mouse pointer. Point targetPoint = myListView.PointToClient(new Point(e.X, e.Y)); // Retrieve the index of the item closest to the mouse pointer. int targetIndex = myListView.InsertionMark.NearestIndex(targetPoint); // Confirm that the mouse pointer is not over the dragged item. if (targetIndex > -1) { // Determine whether the mouse pointer is to the left or // the right of the midpoint of the closest item and set // the InsertionMark.AppearsAfterItem property accordingly. Rectangle itemBounds = myListView.GetItemRect(targetIndex); if ( targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) ) { myListView.InsertionMark.AppearsAfterItem = true; } else { myListView.InsertionMark.AppearsAfterItem = false; } } // Set the location of the insertion mark. If the mouse is // over the dragged item, the targetIndex value is -1 and // the insertion mark disappears. myListView.InsertionMark.Index = targetIndex; }
// Moves the insertion mark as the item is dragged. void myListView_DragOver( Object^ /*sender*/, DragEventArgs^ e ) { // Retrieve the client coordinates of the mouse pointer. Point targetPoint = myListView->PointToClient( Point(e->X,e->Y) ); // Retrieve the index of the item closest to the mouse pointer. int targetIndex = myListView->InsertionMark->NearestIndex( targetPoint ); // Confirm that the mouse pointer is not over the dragged item. if ( targetIndex > -1 ) { // Determine whether the mouse pointer is to the left or // the right of the midpoint of the closest item and set // the InsertionMark.AppearsAfterItem property accordingly. Rectangle itemBounds = myListView->GetItemRect( targetIndex ); if ( targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) ) { myListView->InsertionMark->AppearsAfterItem = true; } else { myListView->InsertionMark->AppearsAfterItem = false; } } // Set the location of the insertion mark. If the mouse is // over the dragged item, the targetIndex value is -1 and // the insertion mark disappears. myListView->InsertionMark->Index = targetIndex; }
// Moves the insertion mark as the item is dragged. private void myListView_DragOver(Object sender, DragEventArgs e) { // Retrieve the client coordinates of the mouse pointer. Point targetPoint = myListView.PointToClient( new Point(e.get_X(), e.get_Y())); // Retrieve the index of the item closest to the mouse pointer. int targetIndex = myListView.get_InsertionMark(). NearestIndex(targetPoint); // Confirm that the mouse pointer is not over the dragged item. if (targetIndex > -1) { // Determine whether the mouse pointer is to the left or // the right of the midpoint of the closest item and set // the InsertionMark.AppearsAfterItem property accordingly. Rectangle itemBounds = myListView.GetItemRect(targetIndex); if (targetPoint.get_X() > itemBounds.get_Left() + itemBounds.get_Width() / 2) { myListView.get_InsertionMark().set_AppearsAfterItem(true); } else { myListView.get_InsertionMark().set_AppearsAfterItem(false); } } // Set the location of the insertion mark. If the mouse is // over the dragged item, the targetIndex value is -1 and // the insertion mark disappears. myListView.get_InsertionMark().set_Index(targetIndex); } //myListView_DragOver

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からListViewInsertionMark.Index プロパティを検索する場合は、下記のリンクをクリックしてください。

- ListViewInsertionMark.Index プロパティのページへのリンク