Notes on working with WinForms DataBinding
- Always handle BindingSource.ListChanged event to avoid unpleasant surprises with BindingSource.Current changing on its own upon EndEdit.
- In master detail, call master binding source EndEdit() before calling detail binding source EndEdit
- Use ComboBox SelectionChangeCommitted instead of SelectedIndexChanged. The latter will fire during initial databinding
- To set default values after BindingSource.AddNew() is called, use the AddingNewEvent
AddingNewEventHandler h = (o, e) => { WorkDataSet.SessionRow session = (sessionBindingSource.List as DataView).AddNew().Row as WorkDataSet.SessionRow; session.UserID = Program.Server.UserID; session.SessionID = Guid.NewGuid().ToString(); session.Duration = 0.5M; sessionBindingSource.MoveLast(); e.NewObject = session; }; sessionBindingSource.AddingNew += h; sessionBindingSource.AddNew(); sessionBindingSource.AddingNew -= h;
About this entry
You’re currently reading “ Notes on working with WinForms DataBinding ,” an entry on Chui's Counterpoint
- Published:
- 7.23.11 / 9pm
- Category:
- .Net, Engineering notes
Comments are closed
Comments are currently closed on this entry.