开发者

WinForms binding

I have some controls bound to a BindingSource control.开发者_如何转开发

I want to do a calculation when the value changes in one control and set the result on another control.

Do I update the textbox the property is bound to or do I update the underlying entity which would update the control anyway (I hope)?

When I change combobox A (OnPropertyChange) textbox B is updated with the new calculated result. This works fine, but I have noticed that when I leave combobox A it reverts back to its original value. What is going on here!

Private Sub ComboBoxEditCostCode_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxEditCostCode.EditValueChanged
    Select Case ComboBoxEditCostCode.EditValue
        Case "7" 
            CType(TransactionEntityBindingSource.Current, TblTransactionsEntity).Qbdescription = "7-is here" 

        Case "2" 
            CType(TransactionEntityBindingSource.Current, TblTransactionsEntity).Qbdescription = "2-is here" 

        Case Else
            CType(TransactionEntityBindingSource.Current, TblTransactionsEntity).Qbdescription = "7-is here"
    End Select
End Sub


if we bind a control to a source, then if the source changes, we can make the its value automatically reflected in the control. About the problem you are facing, it would be better if you show the code snippet.


Tell more about your changing, how second text box is bound?
You have to change your initial data instead of changing textbox b value.
Also when textbox A loses it focus raises EndEdit event and I think binding mechanism refreshes value in textbox B.
You can control on which action editing is done when you setting your binding to textboxes.


as a rule of thumb, if you are using a binding source you always CRUD the data through it. Don't forget to call BindingSource.EndEdit when you are done, hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜