Export (0) Print
Expand All

CurrencyManager.Position Property

Gets or sets the position you are at within the list.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public override int Position { get; set; }
/** @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)

Property Value

A number between 0 and Count minus 1.

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

Therefore, the Position determines the currency, or place in the list, of all controls bound to the same CurrencyManager. For example, imagine a list consisting of two columns called "FirstName" and "LastName". 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. 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. 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".

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft