次の方法で共有


CurrencyManager.Refresh メソッド

バインド コントロールを強制的に再作成します。

Public Sub Refresh()
[C#]
public void Refresh();
[C++]
public: void Refresh();
[JScript]
public function Refresh();

解説

データ ソースが変更時の通知をサポートしていない場合 (Array など) は、 Refresh メソッドを使用します。

使用例

配列を作成し、それを TextBox コントロールにバインドしてから、値を 1 つ変更する例を次に示します。 Refresh メソッドを呼び出して、 TextBox コントロールによって表示される値を更新できます。

 
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

[C#] 
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();
 }
      

[C++] 
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] = String::Format( S"item {0}", __box(i));
    }
    textBox1->DataBindings->Add (S"Text",myArray,S"");
    // Change one value.
    myArray[0]= S"New value";

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

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

[JScript] 
private function DemonstrateRefresh(){
    // Create an array with ten elements and bind to a TextBox.
    var myArray : String[] = new String[10];
    for(var i : int = 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 function RefreshGrid(dataSource){
    var myCurrencyManager : CurrencyManager = CurrencyManager(this.BindingContext[dataSource]);
    myCurrencyManager.Refresh();
 }
      

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

CurrencyManager クラス | CurrencyManager メンバ | System.Windows.Forms 名前空間