残高ラベルが最初に数値にバインドされた後、データソースを再度変更しても値は再び更新されません。DataBindingでラベルを更新する
データベースオブジェクトが変更された後、自動的にWindowsフォームラベルを更新したいのですが、constructorData.BankAccount
に再プルします。でもConstructorData
クラスでINotifyPropertyChanged
を実装し、
bankAccountBindingSource.DataSource = constructorData.BankAccount;
あなたはBankAccount
インスタンスに直接結合する:(フォームのロード内)ここにいるので
//
// lblAccountBalance
//
this.lblAccountBalance.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblAccountBalance.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bankAccountBindingSource, "Balance", true));
this.lblAccountBalance.Location = new System.Drawing.Point(482, 71);
this.lblAccountBalance.Name = "lblAccountBalance";
this.lblAccountBalance.Size = new System.Drawing.Size(196, 23);
this.lblAccountBalance.TabIndex = 7;
this.lblAccountBalance.Text = "label1";
わかりません。 – LarsTech
@LarsTechビジュアルスタジオのデータソースツリーからラベルをドラッグして、自動的にバインディングソースを作成し、ラベルをバインドしました。ラベルのどのコードが役に立ちますか? – Ben
[クリック](http://stackoverflow.com/q/1315621/1997232)。 – Sinatr