CurrencyManager.Refresh CurrencyManager.Refresh CurrencyManager.Refresh CurrencyManager.Refresh Method

定义

强制重新填充数据绑定列表。Forces a repopulation of the data-bound list.

public:
 void Refresh();
public void Refresh ();
member this.Refresh : unit -> unit
Public Sub Refresh ()

示例

下面的代码示例创建一个数组,并将其绑定到TextBox控制,然后更改一个值。The following code example creates an array and binds it to a TextBox control, and then changes one value. Refresh方法可以调用以更新显示的值TextBox控件。The Refresh method can be called to update the value displayed by the TextBox control.

void DemonstrateRefresh()
{
   
   // Create an array with ten elements and bind to a TextBox.
   array<String^>^myArray = gcnew array<String^>(10);
   for ( int i = 0; i < 10; i++ )
   {
      myArray[ i ] = String::Format( "item {0}", i );

   }
   textBox1->DataBindings->Add( "Text", myArray, "" );
   
   // Change one value.
   myArray[ 0 ] = "New value";
   
   // Uncomment the next line to refresh the CurrencyManager.
   // RefreshGrid(myArray);
}

void RefreshGrid( Object^ dataSource )
{
   CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[ dataSource ]);
   myCurrencyManager->Refresh();
}

private void DemonstrateRefresh(){
    // Create an array with ten elements and bind to a TextBox.
    string[] myArray= new string[10];
    for(int i = 0; i <10; i++){
       myArray[i] = "item " + i;
    }
    textBox1.DataBindings.Add ("Text",myArray,"");
    // Change one value.
    myArray[0]= "New value";

    // Uncomment the next line to refresh the CurrencyManager.
    // RefreshGrid(myArray);
 }
 private void RefreshGrid(object dataSource){
    CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[dataSource];
    myCurrencyManager.Refresh();
 }
      
Private Sub DemonstrateRefresh()
    ' Create an array with ten elements and bind to a TextBox.
    Dim myArray(9) As String
    Dim i As Integer
    For i = 0 To 9
        myArray(i) = "item " & i
    Next i
    textBox1.DataBindings.Add("Text", myArray, "")
    ' Change one value.
    myArray(0) = "New value"

    ' Uncomment the next line to refresh the CurrencyManager.
    ' RefreshGrid(myArray);

End Sub 'DemonstrateRefresh

Private Sub RefreshGrid(dataSource As Object)
    Dim myCurrencyManager As CurrencyManager = CType(Me.BindingContext(dataSource), CurrencyManager)
    myCurrencyManager.Refresh()
End Sub 'RefreshGrid

注解

使用Refresh方法时数据源不支持通知更改时 (例如,如果它是Array)。Use the Refresh method when the data source does not support notification when it is changed (for example, if it is an Array).

适用于

另请参阅