CurrencyManager.Position CurrencyManager.Position CurrencyManager.Position CurrencyManager.Position Property

定义

获取或设置在列表中的位置。Gets or sets the position you are at within the list.

public:
 virtual property int Position { int get(); void set(int value); };
public override int Position { get; set; }
member this.Position : int with get, set
Public Overrides Property Position As Integer

属性值

0 和 Count 减 1 之间的一个数。A number between 0 and Count minus 1.

示例

下面的代码示例使用Position允许使用包含列表的导航属性。The following code examples use the Position property to allow navigation through a list.

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.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 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
   

注解

重要属性之一CurrencyManager类是Position属性。An important property of the CurrencyManager class is the Position property. 在项的列表,可以查看只有一个项目超过整个列表。In a list of items, you can view only one item out of the entire list. 若要确定查看哪一项,请设置Position为 0 (列表开头) 之间的数值和Count减 1 (列表的末尾)。To determine which item is viewed, set the Position to a number between 0 (the beginning of the list) and Count minus 1 (the end of the list).

因此,Position货币或在列表中,所有控件绑定到相同的位置确定CurrencyManagerTherefore, the Position determines the currency, or place in the list, of all controls bound to the same CurrencyManager. 例如,假设名为"FirstName"和"LastName"的两个列组成的列表。For example, imagine a list consisting of two columns called "FirstName" and "LastName". 两个TextBox控件绑定到相同的列表; 第一个控件绑定到的第一列和第二个控件都绑定到第二个列。Two TextBox controls are bound to the same list; the first control is bound to the first column, and the second control is bound to the second column. Position的常见CurrencyManager设置到第三个位置,这两个控件将显示该位置在列表中适当的值。When the Position of the common CurrencyManager is set to the third position, both controls display the appropriate values for that position in the list. 换而言之,如果三个位置处的项包含"John"名和姓氏"Smith",在绑定的控件将显示"John"和"Smith"。In other words, if the item at position three consists of the first name "John" and the last name "Smith", the bound controls will display "John" and "Smith".

适用于

另请参阅