I am a little bit puzzled as to how I can optimize my program by utlizing DataBindings. My program uses several Linq2SQL bound Objects storing the Data. All ORM objects are stored in a hierarchy. In a second GUI project I am displaying this data in some Text and Combo Box fields.
The data structure hierarchy is as follows:
JobManagercontains a Dictionary ofJobs- Each Job contains a Dictionary of
Jobitems - Each Jobitem contains exactly one
Article
Job, Jobitem and Article each are Linq2SQL objects, representing a ORM.
Now I have a GUI with 2 list views and a tab pane. The tab pane displays the properties of jobs, jobitems and articles and offers the possibility to modify jobs and jobitems. The GUI should behave like this:
- When a
Jobis selected in the first ListView, the related jobitems will be shown in the second ListView and detail information about the job are shown in the tab pane. - When a
Jobitemis selected in the second ListView, the jobitem details and article details are shown in the tab pane, but only the Jobitem info is editable. - When changes are done, the user has to intentionally save them. Otherwise the changes should be discarded and not synced to the database.
How can I achieve this behaviour with DataBinding?
Especially, can I bind a complete collection to a single TextField once and shift through its position dictated by the selection in the ListViews? Or do I have to add and remove individual DataBindings on a per Job basis for every selection the user conducts?
Do you really mean “Dictionary”? Winform binding is OK with lists (
IList/IListSource), but not with dictionary. Additionally,ListViewisn’t quite as easy to bind to as some other controls.Other than that, it should work purely using the mapping names – I’ll try to do a simple example…
Edit with basic example from Northwind; note that the data-context should ideally not be long lived; you may also want to look at things like repository implementations rather than direct binding:
As an aside – note that the syntax:
Is equivalent to:
(I only add this as it is a common question)