嵌套的 WPF 数据网格

问题描述:

我有一个 DataGrid(来自工具包),我想在 DataGrid.RowDetailsTemplate 中嵌套另一个 DataGrid.诀窍是我想从主网格中的一个表中取回数据,然后根据行选择从另一个表中获取其他详细信息,并将其显示在详细信息模板的 DataGrid 中.

I have a DataGrid (from the toolkit) and I want to nest another DataGrid in the DataGrid.RowDetailsTemplate. The trick is I want to bring back the data from one table in the main grid and then based on row selection go and get additonal detail from a different table and show it in the DataGrid in the detail template.

这很容易在 2 个单独的 DataGrids 中完成,但我无法让它与嵌套版本一起工作.

This is easy enough to do in 2 seperate DataGrids but I am having trouble getting it to work with the nested version.

这甚至可能吗?如果是这样,有人可以指出我正确的方向.我应该注意到我使用 LinqToSql 类来填充数据.

Is this even possible? If so, could someone point me in the right direction. I should note I am using LinqToSql clases to populate the data.

感谢您的考虑.-乔尔

如果您使用的是 LinqToSQL,则可以使用关联轻松完成此操作.在我的实践中,我创建了两个表:

If you are using LinqToSQL you can easily do this using an association. In my practice I have created two tables:

GuyTable

  • 名字
  • 姓氏
  • 唯一标识

GuyActionsTable

GuyActionsTable

  • 唯一标识
  • GuyID
  • 动作说明

我创建了从 GuyTable.UniqueID 到 GuyActionsTable.GuyID 的一对多关系,称为GuyActions"

I created a one-to-many relationship from GuyTable.UniqueID to GuyActionsTable.GuyID called "GuyActions"

然后我像这样绑定我的 DataGrid.请原谅我手工操作时出现的任何错误:

I then bind my DataGrid like this. Excuse any errors as I am doing this by hand:

<w:DataGrid ItemsSource={Binding Source={StaticResource YourDataSource}}>
<w:DataGrid.RowDetailsTemplate>
    <DataTemplate>
        <w:DataGrid ItemsSource={Binding GuyActions}>
            <w:DataGrid.Columns>
                <w:DataGridTextColumn Header="Action" DisplayMemberBinding="{Binding Action_Description}" />
            </w:DataGrid.Columns>
        </w:DataGrid>
    </DataTemplate>
</w:DataGrid.RowDetailsTemplate>
<w:DataGrid.Columns>
    <w:DataGridTextColumn Header="First Name" DisplayMemberBinding="{Binding First_Name}" />
    <w:DataGridTextColumn Header="Last Name" DisplayMemberBinding="{Binding Last_Name}" />
</w:DataGrid.Columns>