XamDataGrid——在运行时添加列

本文关键字:添加 XamDataGrid 运行时 | 更新日期: 2023-09-27 18:04:26

我有一个XamDataGrid,并在运行时提供一个数据源。我想在运行时隐藏一些基于用户输入字段的列。在这里,相同的网格可以被3个不同的表用来显示数据。

请给我一些建议来做这件事。

 private void EditAllocations_Click(object sender, RoutedEventArgs e)
    {
        ObservableCollection<LobAllocation> ds = _controller.PlanitariumModel.Entity.LobAllocations;
        if (editGridClickCheck((Button)sender, ds.Count))
        {
            EditGrid.DataSource = ds
        }
    }

数据源有以下字段:

    AllocationKey, Description, Allocation, ParentAllocationPct, SubAllocation1, SubAllocation2, SubAllocation3, SubAllocation4, SubAllocation5, SubAllocation6, SubAllocation7, SubAllocation8, SubAllocation9

现在根据用户输入,我想选择这些字段的组合,这些字段反过来应该允许在XamDataGrid中进行编辑。

XamDataGrid——在运行时添加列

一种选择是定义字段布局中所有可能的字段,然后根据所选择的内容设置它们的可见性。下面的例子可能对你有用:http://www.infragistics.com/community/blogs/josh_smith/archive/2008/06/06/binding-a-xamdatagrid-field-property.aspx

在知道需要哪些字段之后,还可以使用其他选项来定义布局。从问题中提供的细节无法确定哪种方法最有效。