CollectionView.MoveCurrentTo(Object) メソッド
定義
指定された項目をビュー内の CurrentItem に設定します。Sets the specified item to be the CurrentItem in the view.
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 として設定する項目。The item to set as the CurrentItem.
戻り値
結果として得られる CurrentItem がビュー内に存在する場合は true
。それ以外の場合は false
。true
if the resulting CurrentItem is within the view; otherwise, false
.
実装
例
このメソッドの使用例を次に示します。The following example demonstrates the use of this method.
// 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 ビュー内のコレクションの先頭の前に配置されます。If the specified item is not found, the method returns false
and the CurrentItem is positioned before the beginning of the collection in the view.
コレクションビューは、現在のレコードポインターの概念をサポートします。Collection views support the concept of a current record pointer. コレクションビュー内のオブジェクト間を移動すると、レコードポインターが移動されます。これにより、コレクション内の特定の場所に存在するオブジェクトを取得できます。As you navigate through the objects in a collection view, you are moving a record pointer that allows you to retrieve the object that exists at that particular location in the collection. 詳細については、「 データバインディングの概要」の「コレクションへのバインド」を参照してください。For more information, see "Binding to Collections" in Data Binding Overview.
ビューの現在の項目の詳細については、「」を参照してください CurrentItem 。For more information about the current item of a view, see CurrentItem.