共用方式為


DataRepeater.CurrentItemIndex 屬性

取得或設定目前DataRepeaterItemDataRepeater控制項。

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

'宣告
<BrowsableAttribute(False)> _
Public Property CurrentItemIndex As Integer
[BrowsableAttribute(false)]
public int CurrentItemIndex { get; set; }
[BrowsableAttribute(false)]
public:
property int CurrentItemIndex {
    int get ();
    void set (int value);
}
[<BrowsableAttribute(false)>]
member CurrentItemIndex : int with get, set
function get CurrentItemIndex () : int 
function set CurrentItemIndex (value : int)

屬性值

類型:Int32
目前 DataRepeaterItem 的索引。

備註

使用這個屬性來傳回,或變更索引CurrentItemDataRepeater控制項。 設定CurrentItemIndex屬性捲動DataRepeaterItem具有對等的索引檢視。

注意事項注意事項

DataRepeaterItem會完全捲動到檢視,使用的最小捲動策略。若要使用的最上層項目對齊DataRepeater,呼叫ScrollItemIntoView方法中,指定true的AlignWithTop參數。

範例

下列範例示範如何使用CurrentItemIndex屬性,以將焦點設定為中的項目DataRepeater控制項,根據搜尋的結果。 這裡假設您有DataRepeater名為控制項DataRepeater1、TextBox名為SearchTextBox,和Button名為SearchButton,而且DataRepeater繫結至 Northwind 資料庫的 Products 資料表的資料來源。

Private Sub SearchButton_Click() Handles SearchButton.Click
    Dim foundIndex As Integer 
    Dim searchString As String
    searchString = SearchTextBox.Text
    foundIndex = ProductsBindingSource.Find("ProductID", 
       searchString)
    If foundIndex > -1 Then
        DataRepeater1.CurrentItemIndex = foundIndex
    Else
        MsgBox("Item " & searchString & " not found.")
    End If 
End Sub
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.");
    }
}

.NET Framework 安全性

請參閱

參考

DataRepeater 類別

Microsoft.VisualBasic.PowerPacks 命名空間

CurrentItemIndexChanged

其他資源

DataRepeater 控制項簡介 (Visual Studio)