【问题标题】:How to check whether a column exists in XamDataGrid or not?如何检查 XamDataGrid 中是否存在列?
【发布时间】:2020-09-23 05:27:52
【问题描述】:

我对 Xaml 还是很陌生。我想从绑定到视图模型中的数据表的XamDataGrid 中隐藏一列“Id”。 我尝试了以下方法:

private void xamDataGrid1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)
{
    xamDataGrid1.FieldLayouts[0].Fields["ID"].Visibility = Visibility.Collapsed;
}

但是当我第一次运行代码时,我得到以下异常:

System.ArgumentException: '未找到密钥'

在运行上述代码之前,有什么方法可以检查 Field["Id"] 是否存在?

【问题讨论】:

    标签: c# infragistics xamdatagrid


    【解决方案1】:

    以下对我有用:

    private void XamDataGrid_RecordsInViewChanged(object sender, Infragistics.Windows.DataPresenter.Events.RecordsInViewChangedEventArgs e)
            {
    int count = 0;
              
                    count = XamDataGrid.DefaultFieldLayout.Fields.Count(field => field.Name.CIeq("Id"));
    
                    if (count > 0)
                        XamDataGrid.DefaultFieldLayout.Fields["Id"].Visibility = Visibility.Collapsed;
                
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-12
      • 2017-01-01
      • 2010-09-18
      • 2010-10-02
      • 2015-11-07
      • 2010-12-21
      • 2010-09-13
      相关资源
      最近更新 更多