嵌套 WPF 数据网格

发布于 2024-07-20 15:57:24 字数 301 浏览 5 评论 0原文

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

这在 2 个独立的 DataGrid 中很容易做到,但我在让它与嵌套版本一起使用时遇到了困难。

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

感谢您的考虑。 -乔尔

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.

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

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.

Thanks for your consideration.
-Joel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乙白 2024-07-27 15:57:24

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

GuyTable

  • 名字 姓氏
  • UniqueID
  • GuyActionsTable

UniqueID

  • GuyID
  • 操作
  • 描述

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

然后像这样绑定我的 DataGrid。 请原谅我手动执行此操作时出现的任何错误:

<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>

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

GuyTable

  • First Name
  • Last Name
  • UniqueID

GuyActionsTable

  • UniqueID
  • GuyID
  • Action Description

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

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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文