databinding to control.tag causes changes to dataset
-
Hi, I currently do the following when closing a form containing editable databound controls (comboboxes mainly).. this.configBindingSource.EndEdit(); if ((bool)this.myDataSet1.HasChanges()) // do some stuff The problem is that if I bind a control's tag to a field in the datatable, the above condition is met even if there are no changes made to the form's controls at all. Even if I bind it to a label.tag, it still triggers a change to the datatable. Is there something I'm doing wrong? Thanks.
Glen Harvy
-
Hi, I currently do the following when closing a form containing editable databound controls (comboboxes mainly).. this.configBindingSource.EndEdit(); if ((bool)this.myDataSet1.HasChanges()) // do some stuff The problem is that if I bind a control's tag to a field in the datatable, the above condition is met even if there are no changes made to the form's controls at all. Even if I bind it to a label.tag, it still triggers a change to the datatable. Is there something I'm doing wrong? Thanks.
Glen Harvy
No you're not doing something wrong, but you have to know something about data binding: Whenever you bind something to a property (
Tag
in your case) that does not have a correspondingPropertyChanged
event (TagChanged
event in your case) then the data binding framework assumes that the value has changed. Therefore the value is written back to the data source even if the value hasn't changed. If this is the reason for your problem then you can: - define that the binding is only unidirectional (from data-source to control and not back). This can be defined somewhere, but I can't remember where (we don't use data binding anymore) - derive a class from that control and implement the TagChanged event - use something better than data binding (MVP)-^-^-^-^-^- no risk no funk ................... please vote ------>
-
No you're not doing something wrong, but you have to know something about data binding: Whenever you bind something to a property (
Tag
in your case) that does not have a correspondingPropertyChanged
event (TagChanged
event in your case) then the data binding framework assumes that the value has changed. Therefore the value is written back to the data source even if the value hasn't changed. If this is the reason for your problem then you can: - define that the binding is only unidirectional (from data-source to control and not back). This can be defined somewhere, but I can't remember where (we don't use data binding anymore) - derive a class from that control and implement the TagChanged event - use something better than data binding (MVP)-^-^-^-^-^- no risk no funk ................... please vote ------>
Thanks for that - in this case I'll handle the situation differently.
Glen Harvy