CollectionView.MoveCurrentTo(Object) Metode

Definisi

Mengatur item yang ditentukan menjadi CurrentItem dalam tampilan.

public:
 virtual bool MoveCurrentTo(System::Object ^ item);
public virtual bool MoveCurrentTo(object item);
abstract member MoveCurrentTo : obj -> bool
override this.MoveCurrentTo : obj -> bool
Public Overridable Function MoveCurrentTo (item As Object) As Boolean

Parameter

item
Object

Item yang akan diatur sebagai CurrentItem.

Mengembalikan

true jika hasilnya CurrentItem ada dalam tampilan; jika tidak, false.

Penerapan

Contoh

Contoh berikut menunjukkan penggunaan metode ini.

// Event handler for the NewColor button
void  OnNewColorClicked(object sender, RoutedEventArgs args)
{
  Button button = (Button)sender;
  ColorItemList colorList = (ColorItemList)button.DataContext;
  CollectionView cv = (CollectionView)CollectionViewSource.GetDefaultView((IEnumerable)colorList);

  // add a new color based on the current one, then select the new one
  ColorItem newItem = new ColorItem((ColorItem)cv.CurrentItem);
  colorList.Add(newItem);
  cv.MoveCurrentTo(newItem);
}
' Event handler for the NewColor button
Private Sub OnNewColorClicked(ByVal sender As Object, ByVal args As RoutedEventArgs)
  Dim button As Button = CType(sender, Button)
  Dim colorList As ColorItemList = CType(button.DataContext, ColorItemList)
  Dim cv As CollectionView = CType(CollectionViewSource.GetDefaultView(CType(colorList, IEnumerable)), CollectionView)

  ' add a new color based on the current one, then select the new one
  Dim newItem As New ColorItem(CType(cv.CurrentItem, ColorItem))
  colorList.Add(newItem)
  cv.MoveCurrentTo(newItem)
End Sub

Keterangan

Jika item yang ditentukan tidak ditemukan, metode akan kembali false dan CurrentItem diposisikan sebelum awal koleksi dalam tampilan.

Tampilan koleksi mendukung konsep penunjuk rekaman saat ini. Saat Anda menavigasi objek dalam tampilan koleksi, Anda memindahkan penunjuk rekaman yang memungkinkan Anda mengambil objek yang ada di lokasi tertentu dalam koleksi. Untuk informasi selengkapnya, lihat "Pengikatan ke Koleksi" di Gambaran Umum Pengikatan Data.

Untuk informasi selengkapnya tentang item tampilan saat ini, lihat CurrentItem.

Berlaku untuk

Lihat juga