-
May 21st, 2009, 10:53 AM
#1
ComboBox binding to another.
I have a business object called Companies which contains a list of Department objects each of which contains list of Employee objects.
On a form I have a combobox to display the companies, combo box to display the departments, and finally a list box to display the employees.
I created a data provider for the companies which the Companies combobox displays. Is it possible, without using event handlers for selection changed, to bind the department combobox with the "Selected" company.Departments and the Employee combobox with the "Selected" department.Employees?
Any clue on how to do this would be appreciated!
Mike B
-
May 26th, 2009, 01:39 AM
#2
Re: ComboBox binding to another.
Setup:
1) Put all the combo boxes within some sort of container, like a StackPanel
2) Assign the Companies business object to the DataContext for the StackPanel
Companies combo box:
3) Set ItemsSource to be "{Binding}"
4) Set IsSynchronizedWithCurrentItem to True
5) Set DisplayMemberPath to be property of Company to display (name of company?)
Departments combo box:
6) Set ItemsSource to be "{Binding}"
7) Set IsSynchronizedWithCurrentItem to True
8) Set DisplayMemberPath to be property of Department to display (name of department?)
9) Finally, to hook the selected selection from the Companies combo box up to the Departments combo box, we will use data binding. This will look something like the following:
{Binding ElementName=companyComboBox, Path=SelectedItem.Departments}
If this much works, you can just repeat the process for your employees combo box.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|