[英]Winforms derived combobox property two way binding
我創建了自定義ComboBox控件,並想將自定義屬性“ ActiveValue”綁定到數據集。 我這樣做的方式是:
cboMyComboBox.DataBindings.Add(New System.Windows.Forms.Binding("ActiveValue", Me.dstDetails, "Table.CBOVALUE", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged, ""))
...
Public Property ActiveValue As String
Get
Return _activeValue
End Get
Set(value As String)
If _activeValue <> value Then
_activeValue = value
Me.Text = _activeValue
End If
End Set
End Property
它從DataSet檢索值,但無法更新。 我選擇不更新什么值都沒有關系。 此屬性是簡單的文本字段。 試圖在派生的ComboBox類上實現INotifyPropertyChanged,但並沒有幫助。 有人可以告訴我問題出在哪里嗎? 謝謝
更新:在我的課程中發現了一個錯誤,但是Rex提供的數據綁定寫方法也很有用,謝謝您的時間。
不知道為什么,因為我看不到您的完整實現,但是如果您真的要強制數據綁定將值寫回到對象,請嘗試DataBinding.WriteValue(),因此在您的ComboBox類中,請在適當的位置(可能在某些文本處)更改的事件處理程序):
theDataBinding = Me.DataBindings(theIndex) ' you may find the binding by the bound field name
theDataBinding.WriteValue()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.