CollectionView.MoveCurrentTo(Object) 方法

定義

將指定項目設定為檢視中的 CurrentItem

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

參數

item
Object

要設定為 CurrentItem 的項目。

傳回

如果產生的 CurrentItem 位於檢視之內,就是 true,否則就是 false

實作

範例

下列範例示範如何使用這個方法。

// 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

備註

如果找不到指定的專案,方法會 false 傳回 , CurrentItem 而且 位於檢視中集合的開頭之前。

集合檢視支援目前記錄指標的概念。 當您巡覽集合檢視中的物件時,您會移動記錄指標,讓您擷取存在於集合中特定位置的物件。 如需詳細資訊,請參閱 資料系結概觀中的。

如需檢視目前專案的詳細資訊,請參閱 CurrentItem

適用於

另請參閱