This is a migrated thread and some comments may be shown as answers.

Data binding to sub-list based on row value

2 Answers 133 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 28 Sep 2011, 04:05 PM
Hi all,

This is probably a very simple WPF binding question (it strikes me that it ought to be!) but I can't find an answer to it so am asking here.

I have a RadDataGrid bound to a collection of business objects (projects, to be specific).
Each project has a lead contact and a customer.
I am displaying customers in a GridViewComboBoxColumn, and contacts in another combo box column.

Currently, I'm data binding Customer combobox to a collection of customers, and the Contacts one to a collection of Contacts, like this:

<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CustomerId}" UniqueName="Customer" Header="Customer" DisplayMemberPath="CustomerName" SelectedValueMemberPath="CustomerId"></telerik:GridViewComboBoxColumn>

and in the code behind:

((GridViewComboBoxColumn)radarGridView.Columns["Customer"]).ItemsSource = customers.Values;

it's working, in that the lead contact and customer for that project are displayed in the grid - but the dropdown list for Contacts contains *all* contacts and I really want to display only Contacts which belong to the selected customer.


I know I could do this by overriding a databinding event on each row and binding the contacts column to a filtered list of contacts, but I would have to do that for every column which relates to another and I can't believe there isn't an easier way.

i.e. in effect I would like to bind the contacts combobox to something along the lines of (yes, I know this isn't valid C# :):

contacts.Where(c => c.CustomerId == <currently selected customer ID>)


What am I missing?

Kev

2 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 28 Sep 2011, 04:25 PM
Hello Kevin,

Would you take a look at this blog post ? Is that the scenario that you want to achieve ?
 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Kevin
Top achievements
Rank 1
answered on 28 Sep 2011, 04:52 PM
Perfect, thankyou!

(as an aside, this would make a really useful addition to the How To section of the documentation)

Kev
Tags
GridView
Asked by
Kevin
Top achievements
Rank 1
Answers by
Maya
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or