I have an observable collection of Teams that are then bound to a RadGridview. No issues here. I am able to fill my grid with the team name in the first column. The second column is going to list the head coach. Inside my team collection i have another collection of KeyPeople which contains the head coach. so im struggling figuring out how to bind this second column to another collection.
i have this in my view model
TeamResults = new ObservableCollection<Teams>(_context.Teams);
KeyPeopleResults = new ObservableCollection<KeyPerson>(TeamResults.Select(x => x.KeyPerson).Where(g => g.RelationshipType == "Coach"));
but i cant bind my gridview to two different data sources. the TeamResults holds everything i need.
You could make a client side property for your Team class.
All bindings for controls based off of ItemsControl bind directly to the individual objects showing in the list-and NOT the list itself. This same concept continues to your VM: simply modifying your ViewModel won't help you either. You need to modify the object itself to contain enough information for the binding objects you create in xaml.
Since you are using WCF RIA Services, you can create client side properties that does work for you. Hopefully you are abstracting out your RIA services into Server-Side libraries and Client-Side libraries.
Simply make a partial of your Team class in the Client-Side library where the DataContext lives and write code similar to this:
public partial Team
{
public KeyPerson HeadCoach
{
get
{
if (this.PeopleInTeam != null && this.PeopleInTeam.Any())
{
return this.PeopleInTeam.FirstOrDefault(g => g.RelationshipType == "Coach"));
}
return null;
}
}
}
Then in your binding you can simply bind to properties in Team:
<data:DataGridTextColumn Binding="{Binding Name}" /> /*Team is implied as the object in each row is a Team*/
<data:DataGridTextColumn Binding="{Binding HeadCoach.Name}" />
<data:DataGridTextColumn Binding="{Binding HeadCoach.PhoneNumber}" />
This is a VERY common technique. It is also the reason we have access to write client side code for the classes generated by WCF RIA services.
I've read your comments about using a separate query to load the head coach. You might want to look into downloading your KeyPeople in the same query as your teams. You can use an .Include
statement on the server to send down the key people.
If this isn't a possible solution, then make HeadCoach a {get;set;}
property in your ClientSide code. Also, since WCF RIA is a navigational system, If you make the separate query on the SAME DataContext as the first query, the key people navigational system will already be setup, thus making your partial class' property automatically work.
Have fun!