두 테이블로 구성된 데이터 세트가 있는데, 간단한 일대 다 많은 부모 자식 관계가 진행됩니다. 예 : 내가 부모 ID 필드에 부모와 자식 사이에 설정된 관계 (ParentChildRelation를) 가지고이 데이터 집합에서 wpf 데이터 격자에있는 데이터 세트에서 관련 데이터를 표시하는 방법
Parent Table
ParentId (int)
Name (string)
Child Table
ChildId (int)
ParentId (int)
Name (string)
. 그리고 만약 내가 programtically Parent.getChildRows() 호출을하면 나는 관계가 좋다는 것을 알기 위해 정확한 관련 자식 레코드를 볼 수있다.
부모 행 목록이있는 데이터 격자를 표시하고 선택한 부모에 대한 하위 레코드 목록을 표시하는 별도의 별도의 DataGrid가 필요합니다.
지금까지 내가 또한 윈도우 생성자의 예에서 자체 창에 대한 데이터 컨텍스트를 설정
private DataSet _parentChildDataSet;
public DataSet ParentChildDataSet
{
get
{
return _parentChildDataSet;
}
set
{
_parentChildDataSet = value;
}
public DataView ParentView
{
get
{
return this.ParentChildDataSet.Tables["Parent"].DefaultView;
}
}
public DataRelation ParentChildRelation
{
get
{
return this.ParentChildDataSet.Relations["Parent_Child"] ;
}
}
이 뒤에 코드에서 내 창;
this.DataContext = this;
내 XAML 내가 dataGrid2에 표시하는 자식 기록을 얻을 수 그러나
<Grid>
<DataGrid ItemsSource="{Binding Path=ParentView}" AutoGenerateColumns="True" Name="dataGrid1">
</DataGrid>
<DataGrid ItemsSource="{Binding Path=ParentChildRelation}" Name="dataGrid2" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" />
</DataGrid.Columns>
</DataGrid>
</Grid>
에서
.이 격자를 datarelation 이름에 바인딩하는 것이 맞습니까?
내 창에서 다른 속성에 바인딩하면;
public DataView ChildrenView
{
get
{
return this.ParentChildDataSet.Tables["Child"].DefaultView;
}
}
그러면 부모님과 관계없이 모든 기록을 볼 수 있습니다.
아무도 내게 줄 수있는 포인터를 주셔서 감사합니다.
그리고 왜 이것이 투표를 거절 했습니까? – Paparazzi
왜 downvoted되었는지 또는 누가 정보를 주셔서 감사하지만 CreateChildView 메서드를 호출하는 대신 xaml을 통해 자식 뷰에 직접 바인딩 할 수있는 방법이 없는지 확인 하시겠습니까? –
물음표가 보입니다. 질문 있니? 작동 했나요? – Paparazzi