CollectionView.MoveCurrentTo(Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Parameters
- item
- Object
The item to set as the CurrentItem.
Returns
true
if the resulting CurrentItem is within the view; otherwise, false
.
Implements
Examples
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
Remarks
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.
For more information about the current item of a view, see CurrentItem.