2013-03-06 66 views
0

撥打SetDataBinding(object DataSource, string DataMember, bool hideNewColumns)時,Key preoperty如何在UltraGrid上設置?我怎樣才能將它設置爲List'1如何爲UltraGridBand設置密鑰?

我有以下形式和類別:

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
     this.ultraGrid2.SetDataBinding(new List<row>(), string.Empty, true); 
     this.ultraGrid2.DisplayLayout.ColumnChooserEnabled = DefaultableBoolean.True; 
     // breakpoint on the above line and run the below immediate window code 
    } 
} 

public class row 
{ 
    public string Name { get; set; } 
    public string Address { get; set; } 
} 

設置數據結合後,下面的代碼總是給我List'1在即時窗口:

this.ultraGrid2.DisplayLayout.Bands[0].Key 
+0

爲什麼我認爲這是一個音樂的問題嗎? – 2013-03-06 20:39:53

回答

1

在定義UltraGridBand對象有一個私有方法,在數據綁定期間被調用,稱爲InitBandKey,並且在此方法中設置密鑰。

這樣做的邏輯是類似以下內容:

CurrencyManager cm = (CurrencyManager)this.bindingManager; 
if (cm.List is ITypedList) 
{ 
    newKey = ((ITypedList)cm.List).GetListName(null); 
} 
else 
{ 
    newKey = cm.List.GetType().Name; 
}  

在你的榜樣,你所得到的(new List<row>()).GetType().Name

結果您可以定義從List<row>派生的類,然後名稱那個班將是樂隊的關鍵。例如:

public class CustomList:List<row> 
{ 

} 

再到SetDataBinding在這個例子中更新的呼叫:

this.ultraGrid1.SetDataBinding(new CustomList(), string.Empty, true); 
0

嘗試設置的Key設計時Band[0]

一般波段[X]。重點是綁定數據表/數據視圖的名稱,但在List<T>情況下,沒有名稱使用也許這自動地被控制

+0

不幸的是,這給了我一個NotSupportedException,聲明「Band key can not be set。」。 – 2013-03-06 22:23:35

+0

奇怪的是,現在只需要在WinForms解決方案中的一個空的UltraWinGrid上嘗試,我可以設置該屬性。 – Steve 2013-03-06 22:30:40

+0

我仍然得到這個錯誤。該文檔似乎使它聽起來可以,但不應該使用[Key Property](http://help.infragistics.com/Help/NetAdvantage/WinForms/2012.2/CLR4.0/html/Infragistics4.Win.UltraWinGrid .v12.2〜Infragistics.Win.UltraWinGrid.UltraGridBand〜Key.html)。 – 2013-03-18 19:22:31

相關問題