Hi there,
I have a question about databinding. This is the scenario
I have this application that I created (just a little test...) and this is the code that sets the listbox itemsource
In the XAML I have two stack panels - one on the left with the listbox in it and one the right, it contains just one textbox, what I have done is set the right hand stackpanel's datacontext to the listbox like so...Code:var q = from e in dc.Employees join c in dc.Contacts on e.ContactID equals c.ContactID select c; EmployeesListBox.ItemsSource = q;
Then - in the text box I set the path to FirstName - see the following code.Code:DataContext="{Binding ElementName=EmployeesListBox, Path=SelectedItem}"
Now - as I click through the names in the listbox the textbox updates nicely. Also - the listbox updates as well cause by default the databinding is going two ways.Code:<TextBox Text="{Binding Path=FirstName}" ></TextBox>
This leads me to my question(s) - two really.
One - What is the best way to save that data back to the database if I wanted to?
Second - this is more in-depth... You will notice that I am only selecting one table even though I am doing a join in the query. That is because the object that represents the table implements INotifyPropertyChanged. What happens if I want to do something like the following.
Now it is broken cause I am assuming the change notification isn't there. What is the best way to handle this? Even if I was OK with selecting everything from the Contacts Table and everything from the Employees table how would I tell it to you "both" of those objects?Code:var q = from e in dc.Employees join c in dc.Contacts on e.ContactID equals c.ContactID select new { e.EmployeeID, c.LastName, c.FirstName };
I am new to this stuff so I have a lot to learn so forgive me if this example seems amateurish it is just that there is SOOO much online that it is almost more confusing the more you read...
Thanks for any advice.




Reply With Quote