2013-03-06 95 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

相关问题