1

这是我在 StackOverflow 上的第一个问题,所以我希望我没有做错任何事!对不起,如果是这样!我需要一些帮助,因为我找不到我的问题的解决方案。当然,我在网上到处搜索,但找不到它(由于声誉低,无法发布我正在使用的链接:()。此外,我是 C# 和 WPF 的新手(以及自学)。我曾经在 C++/Qt 中工作,所以我不知道 WPF 中的一切是如何工作的。对不起,我的英语,我是法国人。

我的问题

我的基本课程是员工可以使用计算机。计算机的 id 和使用日期存储在类Connection中。我想在 DataGrid 和 RowDetailsTemplate 中显示列表信息,如下所示:

在此处输入图像描述

所以它会绑定到Employee类,但也绑定到Connection只有属性的最后一个值的类(这里是列表“计算机 ID”的最后一个值和最后一台计算机上列表“连接日期”的最后一个值) . 所以它是不同列表中的一个循环。我该怎么做 ?

是不是做的太多了?:(我成功获取了员工信息,但我不知道如何绑定计算机列表。当我尝试时,它显示“(集合)”,所以它不会进入列表:(

问题总结

  1. 如何显示/绑定列表中的值和来自不同类的值DataGrid
  2. 如何将列表的所有值显示到RowDetailsTemplate?

在 Windows 7 和 Visual Studio 2010 Pro 版本下。

4

2 回答 2

1

我建议你熟悉一下 MVVM 模式,以防你还没有……这是非常基本的,所以你想修改/设置它的样式以获得你想要的 ^_^...

    <DataGrid ItemsSource="{Binding Employees}">
        <DataGrid.Columns>
            <DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"/>
            <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/>
            <DataGridTextColumn Header="Gender" Binding="{Binding Gender}"/>
            <DataGridTextColumn Header="Last computer used" Binding="{Binding LastComputerUsed}"/>
            <DataGridTextColumn Header="Last connection date" Binding="{Binding LastConnectionDate}"/>
        </DataGrid.Columns>
        <DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <DataGrid ItemsSource="{Binding ComputerIDs}">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Computer ID" Binding="{Binding ID}"/>
                        <DataGridTemplateColumn>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <ListView ItemsSource="{Binding ConnectionDates}"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </DataTemplate>
        </DataGrid.RowDetailsTemplate>
    </DataGrid>
于 2013-10-24T18:53:10.723 回答
0

Lets try,

You can create a class named EmployeeConnection that will have

public Employee Employee { get; private set; } public List Connections { get; private set; }

So, every row in your gridview will have 1 Employee and columns with Connection.

You have to make EmployeeConnection as your gridview Data Source.

could be?

于 2013-10-24T18:20:12.680 回答