CurrencyManager.Position 属性

获取或设置在列表中的位置。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Overrides Property Position As Integer
用法
Dim instance As CurrencyManager
Dim value As Integer

value = instance.Position

instance.Position = value
public override int Position { get; set; }
public:
virtual property int Position {
    int get () override;
    void set (int value) override;
}
/** @property */
public int get_Position ()

/** @property */
public void set_Position (int value)
public override function get Position () : int

public override function set Position (value : int)

属性值

0 和 Count 减 1 之间的一个数。

备注

CurrencyManager 类的一个重要属性是 Position 属性。在项列表中,只能查看整个列表的其中一项。若要确定查看的是哪一项,请将 Position 设置为 0(列表开头)和 Count 减一(列表末尾)之间的一个数。

因此,Position 确定绑定到同一 CurrencyManager 的所有控件在列表中的当前位置。例如,如果列表包含两列,分别名为“FirstName”和“LastName”。两个 TextBox 控件绑定到该列表;第一个控件绑定到第一列,第二个控件绑定到第二列。如果公共的 CurrencyManagerPosition 设置为第三个位置,则两个控件都显示列表中该位置的相应值。换言之,如果第三个位置的项由名字“John”和姓氏“Smith”组成,则这两个绑定控件分别显示“John”和“Smith”。

示例

下面的代码示例使用 Position 属性实现对列表的导航。

Private Sub MoveNext(ByVal myCurrencyManager As CurrencyManager)
    If myCurrencyManager.Count = 0 Then
       Console.WriteLine("No records to move to.")
       Exit Sub
    End If
 
    If myCurrencyManager.Position = myCurrencyManager.Count - 1 Then 
       MessageBox.Show("You're at end of the records")
    Else
       myCurrencyManager.Position += 1
    End If
 End Sub
 
 Private Sub MoveFirst(ByVal myCurrencyManager As CurrencyManager)
    If myCurrencyManager.Count = 0 Then
       Console.WriteLine("No records to move to.")
       Exit Sub
    End If
 
    myCurrencyManager.Position = 0
 End Sub
 
 Private Sub MovePrevious(ByVal myCurrencyManager As CurrencyManager)
    If myCurrencyManager.Count = 0 Then
       Console.WriteLine("No records to move to.")
       Exit Sub
    End If
 
    If myCurrencyManager.Position = 0 Then
       MessageBox.Show("You're at the beginning of the records.")
    Else
       myCurrencyManager.Position -= 1
    End if
 End Sub
 
 Private Sub MoveLast(ByVal myCurrencyManager As CurrencyManager)
    If myCurrencyManager.Count = 0 Then
       Console.WriteLine("No records to move to.")
       Exit Sub
    End If
 
    myCurrencyManager.Position = myCurrencyManager.Count - 1
 End Sub
   
private void MoveNext(CurrencyManager myCurrencyManager){
    if(myCurrencyManager.Count == 0) {
       Console.WriteLine("No records to move to.");
       return;
    }
    if (myCurrencyManager.Position == myCurrencyManager.Count - 1){
       Console.WriteLine("You're at end of the records");
    }
    else{
      myCurrencyManager.Position += 1;
    }
 }
 
 private void MoveFirst(CurrencyManager myCurrencyManager){
    if(myCurrencyManager.Count == 0) {
       Console.WriteLine("No records to move to.");
       return;
    }
 
    myCurrencyManager.Position = 0;
 }
 
 private void MovePrevious(CurrencyManager myCurrencyManager){
    if(myCurrencyManager.Count == 0) {
       Console.WriteLine("No records to move to.");
       return;
    }
    if(myCurrencyManager.Position == 0) {
       Console.WriteLine("You're at the beginning of the records.");
    }   
    else{
       myCurrencyManager.Position -= 1;
    }
 }
 
 private void MoveLast(CurrencyManager myCurrencyManager){
    if(myCurrencyManager.Count == 0) {
       Console.WriteLine("No records to move to.");
       return;
    }
    myCurrencyManager.Position = myCurrencyManager.Count - 1;
 }
   
private:
   void MoveNext( CurrencyManager^ myCurrencyManager )
   {
      if ( myCurrencyManager->Count == 0 )
      {
         Console::WriteLine( "No records to move to." );
         return;
      }

      if ( myCurrencyManager->Position == myCurrencyManager->Count - 1 )
      {
         Console::WriteLine( "You're at end of the records" );
      }
      else
      {
         myCurrencyManager->Position += 1;
      }
   }

   void MoveFirst( CurrencyManager^ myCurrencyManager )
   {
      if ( myCurrencyManager->Count == 0 )
      {
         Console::WriteLine( "No records to move to." );
         return;
      }

      myCurrencyManager->Position = 0;
   }

   void MovePrevious( CurrencyManager^ myCurrencyManager )
   {
      if ( myCurrencyManager->Count == 0 )
      {
         Console::WriteLine( "No records to move to." );
         return;
      }

      if ( myCurrencyManager->Position == 0 )
      {
         Console::WriteLine( "You're at the beginning of the records." );
      }
      else
      {
         myCurrencyManager->Position -= 1;
      }
   }

   void MoveLast( CurrencyManager^ myCurrencyManager )
   {
      if ( myCurrencyManager->Count == 0 )
      {
         Console::WriteLine( "No records to move to." );
         return;
      }
      myCurrencyManager->Position = myCurrencyManager->Count - 1;
   }
private void MoveNext(CurrencyManager myCurrencyManager)
{
    if (myCurrencyManager.get_Count() == 0) {
        Console.WriteLine("No records to move to.");
        return ;
    }
    if (myCurrencyManager.get_Position() == 
        myCurrencyManager.get_Count() - 1) {
        Console.WriteLine("You're at end of the records");
    }
    else {
        myCurrencyManager.set_Position(
            myCurrencyManager.get_Position() + 1);
    }
} //MoveNext

private void MoveFirst(CurrencyManager myCurrencyManager)
{
    if (myCurrencyManager.get_Count() == 0) {
        Console.WriteLine("No records to move to.");
        return ;
    }
    myCurrencyManager.set_Position(0);
} //MoveFirst

private void MovePrevious(CurrencyManager myCurrencyManager)
{
    if (myCurrencyManager.get_Count() == 0) {
        Console.WriteLine("No records to move to.");
        return;
    }
    if (myCurrencyManager.get_Position() == 0) {
        Console.WriteLine("You're at the beginning of the records.");
    }
    else {
        myCurrencyManager.set_Position(
            myCurrencyManager.get_Position() - 1);
    }
} //MovePrevious

private void MoveLast(CurrencyManager myCurrencyManager)
{
    if (myCurrencyManager.get_Count() == 0) {
        Console.WriteLine("No records to move to.");
        return ;
    }
    myCurrencyManager.set_Position(myCurrencyManager.get_Count() - 1);
} //MoveLast
private function MoveNext(myCurrencyManager : CurrencyManager){
    if(myCurrencyManager.Count == 0) {
       Console.WriteLine("No records to move to.");
       return;
    }
    if (myCurrencyManager.Position == myCurrencyManager.Count - 1){
       Console.WriteLine("You're at end of the records");
    }
    else{
      myCurrencyManager.Position += 1;
    }
 }
 
 private function MoveFirst(myCurrencyManager : CurrencyManager){
    if(myCurrencyManager.Count == 0) {
       Console.WriteLine("No records to move to.");
       return;
    }
 
    myCurrencyManager.Position = 0;
 }
 
 private function MovePrevious(myCurrencyManager : CurrencyManager){
    if(myCurrencyManager.Count == 0) {
       Console.WriteLine("No records to move to.");
       return;
    }
    if(myCurrencyManager.Position == 0) {
       Console.WriteLine("You're at the beginning of the records.");
    }   
    else{
       myCurrencyManager.Position -= 1;
    }
 }
 
 private function MoveLast(myCurrencyManager : CurrencyManager){
    if(myCurrencyManager.Count == 0) {
       Console.WriteLine("No records to move to.");
       return;
    }
    myCurrencyManager.Position = myCurrencyManager.Count - 1;
 }
   

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

CurrencyManager 类
CurrencyManager 成员
System.Windows.Forms 命名空间
CurrencyManager.List 属性
CurrencyManager.Count 属性
CurrencyManager.Current 属性