I have several controls in a winform application that I added databindings to using code.
Dim tblWrapper As ObliqueQCAndSpliceTool.TableWrapper = New ObliqueQCAndSpliceTool.TableWrapper(tbl, idField.Name)
tblWrapper.UseCVDomains = True
bindSource = New BindingSource
bindSource.DataSource = tblWrapper
bindMgr = BindingContext(bindSource)
bindSource.SuspendBinding()
Dim idBinding As Binding = New Binding("Text", bindSource, idField.Name)
txtPointID.DataBindings.Add(idBinding)
Then I have other code that may automatically change values in these controls as the user moves through records in the list. I have had a request to add a simple button that will disable/re-enable editing for these controls. In other words, when enabled, the user or the program can edit the controls and the new values will be saved in the source dataset. When disabled, the controls should still show the values from the source dataset, but the user nor the program should be able to change those values.
I have looked into the AllowEdit property of both the BindingList (tablewrapper) and BindingSource objects that create the databindings, but have had not luck.
Is there a way to change all databindings to readonly without changing each control or resetting all the bindings?
UPDATE:
I tried the solution provided by @LarsTech, but due to some scope issues surrounding how the bindings were set up, I was unable to modify the update mode without recreating all the bindings. I decided it would be easier to simply disable all the code that programmatically changes the values in the controls and to disable all the controls when the button is set to disabled.
Try specifying the
DataSourceUpdateMode:From DataSourceUpdateMode Enumeration:
You can change this directly:
or