Master/Detail works but why ? and more
-
Hello, I have a listbox of "users", when one is selected I want to display two listboxes: one containing the "reports" associated to the user, the other one the "other" reports. And buttons to move reports between the two listboxes. Very common scenario. Users and reports are stored in a database accessed via ADO.NET. I have the following tables:
User: ReportingUser varchar(20) primary key
Reporting: ReportingCode varchar(20) primary key, ReportingName varchar(20)
ReportingUser: ReportingUser varchar(20), ReportingCode varchar(20)I imported the tables in designer and added two Relations: User_ReportingUser: ReportingUser.ReportingUser *->1 User.ReportingUser FK_Reporting_ReportingUser: ReportingUser.ReportingCode *->1 Reporting.ReportingCode The first relation is what my window edits. The second if for fishing the report name and display that instead of the report code. I have the following XAML:
...and Window_Loaded handler:
userAdapter = new UserTableAdapter(); reportingUserAdapter = new ReportingUserTableAdapter(); reportingTableAdapter = new ReportingTableAdapter(); dataset = new DNLMHDataSet(); userAdapter.Fill(dataset.User); reportingTableAdapter.Fill(dataset.Reporting); reportingUserAdapter.Fill(dataset.ReportingUser); listBoxUsers.DataContext = dataset.User; listBoxSelectedReporting.DataContext = dataset.User;
It's amazing to see that this suffices to give me master/detail behavior. My first question is: why does this work? Is there a compact explanation of this somewhere ? I googled around and did find information, e.g. about IsSynchronizedWithCurrentItem, but it's not enough to enlighten me. Where is the "current item" stored ? In listBoxUsers ? How is the other listbox aware that the current item has changed ? The "content" of the User_ReportingUser Relation is parameterized by the currently selected user. How does the ItemsSource of the Report listbox know which user is current ? What's the activity diagram ? Also, now I would like to implement the reports that are not selected for the current user. First I tried to create a query for that