Auto-Updating DataBindings
I scoured the code and I can't seem to see how the Projects combobox is updated when a new Project is added to the DB. I've always done this in the past with a fresh DataBinding and an Invalidate().
I do not see this happening. A reference to m_DataLayer is passed in AddProjectForm's ctor, and the add is made in the btnOk Click event handler. What's curious is I do not see any new binding to cbProjects after the add takes place. What's even more curious is that DsProjects exists across a WebServices proxy.
Where is this rebinding automagically happening because I want to add some code that sets cbProjects's SelectedIndex to the project that was just added. I guess I could just set it to Length - 1 after a DialogResult.OK.
Anyone have any ideas?
So - actually the rebinding isn't a rebinding. In order to maintain the UI control DataBindings - the DataLayer updates the DataSet by deleting the rows and re-adding them (and the new one) if the WS call is successful. When a row is deleted, modified, or added - a Changed event is thrown by the DataRow or Table (don't quote me) ... the UI control then re-populates itself.
Looking back on this, the better choice might have been to re-bind to a fresh DataTable and avoid the headache of the UI controls updating at inconvenient times, (on slower machines a few unwanted side-effects can be seen) - but of course half the benefit of DataBinding would be lost, so it’s debatable.
Hope this helps!
Jay Walters