DataRepeater.CurrentItemIndex Property

 

Gets or sets the current DataRepeaterItem in a DataRepeater control.

Namespace:   Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

[BrowsableAttribute(false)]
public int CurrentItemIndex { get; set; }

Property Value

Type: System.Int32

The index of the current DataRepeaterItem.

Use this property to return or change the index of the CurrentItem in a DataRepeater control. Setting the CurrentItemIndex property scrolls the DataRepeaterItem that has the equivalent index into view.

System_CAPS_noteNote

The DataRepeaterItem will be scrolled fully into view using a minimum scroll strategy. To align the item with the top of the DataRepeater, call the ScrollItemIntoView method, specifying true for the AlignWithTop parameter.

The following example demonstrates how to use the CurrentItemIndex property to set the focus to an item in a DataRepeater control, depending on the results of a search. It assumes that you have a DataRepeater control named DataRepeater1, a TextBox named SearchTextBox, and a Button named SearchButton, and that the DataRepeater is bound to a data source for the Northwind database Products table.

private void searchButton_Click(System.Object sender, System.EventArgs e)
{
    int foundIndex;
    string searchString;
    searchString = searchTextBox.Text;
    foundIndex = productsBindingSource.Find("ProductID", searchString);
    if (foundIndex > -1)
    {
        dataRepeater1.CurrentItemIndex = foundIndex;
    }
    else
    {
        MessageBox.Show("Item " + searchString + " not found.");
    }
}
Return to top
Show: