version 3.0, selfserving, sql server
I have been trying to figure out how to use databinding on one of my windows forms in my project and I got it to work but I hope there is an easier way to do what I am trying to do.
I have a datgridview that is bound to a collection called Stores that is filled with the following:
StoreCollection.GetMulti(nothing)
It only a few fields, such as StoreID and name. If a user selects an existing store and selects an edit button, I display another form that uses a binding source that is bound to a stores collection that I create using the following:
Dim filter As New PredicateExpression(StoreFields.LocId = StoreID)
StoreCollection.GetMulti(filter)
On my edit form there are multiple (about 30) different controls that are bound to the StoreCollection. All works fine with an existing record. But, if the user selects a store that does not exist I do the following:
PBStoreLocationBindingSource.AddNew()
In code I set some of the controls to a default value as follows:
TextBox1.Text = 300
ComboBox5.SelectedIndex = 1
The first control on the screen is a textbox that is bound to the field storename. The first problem I had was that everytime I entered a store name in the textbox and went to the next control, ALL of the controls that I had programically filled with the above code would reset. I took care of this by going to the properties of each control under databindings, advanced and changing the Data Source Update Mode to OnPropertyChanged.
With this it looked like it was fine until I actually tried to update a new record. When I tried to update the new record I would get an erro saying that one of the fields, IP1 does not all nulls. The text on the textbox that is bound to that field is infact "0". The way I got around this is by doing the following:
TextBox11.Text = 1
TextBox11.Text = 0
Then the record wrote fine.
Is guess my question is, Do I hve to jump through all of these hoops with the controls and the defaults? Or is there a easier way to accomplish this task?