ListViewInsertionMark.Index Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri vagy beállítja annak az elemnek az indexét, amely mellett megjelenik a beszúrási jel.
public:
property int Index { int get(); void set(int value); };
public int Index { get; set; }
member this.Index : int with get, set
Public Property Index As Integer
Tulajdonság értéke
Annak az elemnek az indexe, amely mellett megjelenik a beszúrási jel, vagy -1, ha a beszúrási jel rejtett.
Példák
Az alábbi példakód bemutatja, hogyan használható a ListView beszúrási jel funkció, és hogyan valósítható meg a húzási elemek átrendezése a szokásos húzási események használatával. A beszúrási jel pozíciója frissül az Control.DragOver esemény kezelőjében. Ebben a kezelőben az egérmutató pozíciója a legközelebbi elem középpontjának összehasonlítása, és az eredmény annak meghatározására szolgál, hogy a beszúrási jel az elem bal vagy jobb oldalán jelenik-e meg.
A teljes példáért tekintse meg az ListViewInsertionMark áttekintési referenciatémakört.
// 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.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 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
Megjegyzések
A beszúrási jel az elem bal oldalán jelenik meg a megadott indexszel, ha a AppearsAfterItem tulajdonság értéke false; ellenkező esetben az elem jobb oldalán jelenik meg. A beszúrási jel automatikusan eltűnik, amikor egy húzott elemet szúr be a ListView.Items gyűjteménybe. Ha manuálisan szeretné eltávolítani a beszúrási jelet, például ha egy elemet magára húz vagy a vezérlőn kívül húz, állítsa az Index értéket -1 értékre.
Ezzel a NearestIndex módszerrel lekérheti egy adott helyhez legközelebb eső elem indexét, például az egérmutató helyét, amikor egy elemet húzási műveletben helyez el.