2013-02-11 66 views
0

我正在研究將三個Excel文件讀入DataTable的應用程序。他們被稱爲變體,套件和零件。變體和套件與DataRelation連接,套件和零件也是如此。WPF DataGrid控件顯示額外列

在程序的一部分中,我使用DataGrid控件通過DataView顯示整個Variants表的內容。問題是,在Variants表中的所有實際列之後,DataGrid顯示一個名爲VariantsKits的最終列,這是Variants和Kits表之間的DataRelation的名稱。

我該怎麼做才能顯示出來?我使用AutoGenerateColumns,因爲我不確切知道哪些列位於導入的Variants Excel文件中。

任何意見,將不勝感激。

回答

1
// You might have to add a reference to the dll first) 
using System.ComponentModel.DataAnnotations; 

[Display(AutoGenerateField = false)] 
public PropertyType ThisIsThePropertyYouDontWantToShowUp { get; set; } 

第二個選項是掛接到上 DataGrid中AutoGeneratingColumn事件,並把它取消列你不想

private void DataGrid_AutoGeneratingColumn(
    object sender, DataGridAutoGeneratingColumnEventArgs e) 
    { 
     if (/* do a check on e.PropertyName or e.PropertyType*/) 
      e.Cancel = true; 
    } 
+0

第二種方法顯然會更加符合如果你實際上沒有你的數據類型的類,你需要什麼。 – 2013-02-11 08:15:39

+0

非常感謝!我用你的第二個建議,它運作良好。 – 2013-02-11 08:24:50