共用方式為


DataRepeater.ScrollItemIntoView 方法 (Int32, Boolean)

捲動指定DataRepeaterItem到檢視中DataRepeater控制項,選擇性地將其對齊控制項的頂端。

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

語法

'宣告
Public Sub ScrollItemIntoView ( _
    index As Integer, _
    alignWithTop As Boolean _
)
public void ScrollItemIntoView(
    int index,
    bool alignWithTop
)
public:
void ScrollItemIntoView(
    int index, 
    bool alignWithTop
)
member ScrollItemIntoView : 
        index:int * 
        alignWithTop:bool -> unit
public function ScrollItemIntoView(
    index : int, 
    alignWithTop : boolean
)

參數

  • alignWithTop
    類型:Boolean

    true若要對齊頂端DataRepeaterItem頂端的控制項。否則, false。

例外狀況

例外狀況 條件
ArgumentOutOfRangeException

指定的值index小於 0 或大於ItemCount-1。

備註

呼叫ScrollItemIntoView方法,以顯示特定DataRepeaterItem中控制項的可見部分。 不會選取項目。 若要選取的項目,設定CurrentItemIndex屬性。

若要對齊控制項的頂端的項目上方,請設定alignWithTop參數true。 如果alignWithTop是false,項目將會最小捲動演算法中,捲動到檢視它不一定要對齊控制項的頂端。

範例

下列程式碼範例示範如何進行第一次顯示的項目中目前選取的項目DataRepeater控制項,並將它與控制項的頂端對齊。 這裡假設您有包含表單的DataRepeater名為控制項DataRepeater1和Button名為控制項SynchButton。

Private Sub SynchButton_Click() Handles SynchButton.Click
    ' If the first displayed item is not the current item. 
    If DataRepeater1.FirstDisplayedItemIndex <> 
      DataRepeater1.CurrentItemIndex Then 
        ' Make it the current item.
        DataRepeater1.CurrentItemIndex = 
          DataRepeater1.FirstDisplayedItemIndex
        ' Align it with the top of the control.
        DataRepeater1.ScrollItemIntoView( 
          DataRepeater1.FirstDisplayedItemIndex, True)
    End If 
End Sub
private void synchButton_Click(System.Object sender, System.EventArgs e)
{
    // If the first displayed item is not the current item. 
    if (dataRepeater1.FirstDisplayedItemIndex != dataRepeater1.CurrentItemIndex)
    // Make it the current item.
    {
        dataRepeater1.CurrentItemIndex = dataRepeater1.FirstDisplayedItemIndex;
        // Align it with the top of the control.
        dataRepeater1.ScrollItemIntoView(dataRepeater1.FirstDisplayedItemIndex, true);
    }
}

.NET Framework 安全性

請參閱

參考

DataRepeater 類別

ScrollItemIntoView 多載

Microsoft.VisualBasic.PowerPacks 命名空間

CurrentItemIndex

FirstDisplayedItemIndex

其他資源

DataRepeater 控制項簡介 (Visual Studio)

如何:搜尋 DataRepeater 控制項中的資料 (Visual Studio)