I have a Datagrid and inside it’s row details template I have another Datagrid
<DataGrid Name="dataGridWorkOrders" ItemsSource="{StaticResource workorders}" >
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<Border BorderThickness="0" Background="BlanchedAlmond" Padding="10">
<DataGrid IsReadOnly="True" AutoGenerateColumns="False" ItemsSource="{Element=dataGridWorkOrders,path=selectedItem}">
</DataGrid>
</Border>
Workorders Collection is like:
class WorkOrders : ObservableCollection<WorkOrder>
{
public WorkOrders()
{
var orderList = OrderDetailsProvider.GetOrders() as List<WorkOrder>;
orderList.ForEach(
order => this.Add(order));
}
The WorkorderClass has following fields exposed as proporties.
private string orderID;
private int totalQuantity;
private string status;
private ObservableCollection<Schedule> scheduleCollection;
Now in my second datagrid I want to bind to ScheduleCollection of the currently selected datagrid
The data context of the
RowDetailsTemplateshould be the selected item — so you should just bind toscheduleCollection:(… and either use
AutoGenerateColumns="true", or add theDataGridColumnsmanually)