简体   繁体   English

XamDataGrid-在运行时添加列

[英]XamDataGrid - adding columns at run time

I have a XamDataGrid and i provide a data source at run time. 我有一个XamDataGrid,我在运行时提供了一个数据源。 I want to hide some columns based on a user input field at run time. 我想在运行时基于用户输入字段隐藏一些列。 Here the same grid can be used by 3 different tables to display data. 在这里,3个不同的表可以使用同一网格来显示数据。

Please give me some inputs to do this.. 请给我一些输入来执行此操作。

 private void EditAllocations_Click(object sender, RoutedEventArgs e)
    {
        ObservableCollection<LobAllocation> ds = _controller.PlanitariumModel.Entity.LobAllocations;

        if (editGridClickCheck((Button)sender, ds.Count))
        {
            EditGrid.DataSource = ds
        }
    }

The datasource has the following fields: 数据源具有以下字段:

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

Now based on the user input, i want to select a combination of these fields which in turn should be allowed to be editable in the XamDataGrid. 现在,基于用户输入,我想选择这些字段的组合,而这些字段又应允许在XamDataGrid中进行编辑。

One option is to define all of the fields in your field layout that are possible and then set the Visibility of them based on what has been selected. 一种选择是定义字段布局中所有可能的字段,然后根据选择的内容设置其可见性。 The example here may be of use to you: http://www.infragistics.com/community/blogs/josh_smith/archive/2008/06/06/binding-a-xamdatagrid-field-property.aspx 此处的示例可能对您有用: http : //www.infragistics.com/community/blogs/josh_smith/archive/2008/06/06/binding-a-xamdatagrid-field-property.aspx

There may be other options where you define the layout after you know what fields are needed as well. 在还知道需要哪些字段之后,可能还有其他选项可以在其中定义布局。 What will work best isn't able to be determined from the details provided in the question. 无法从问题中提供的详细信息中确定最有效的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM