如何将未绑定的列仅添加到 Infragistics UltraGrid 一次而不引发异常?
使用 NetVantage Windows Forms 9.1 UltraGrid,我想添加一些未绑定的列来执行一些简单的计算。第一次在 InitializeLayout 委托中输入此代码时,它发现列尚不存在,然后添加它们。令人惊讶的是,当我获取新数据,重新绑定网格,然后再次输入这个委托时,它仍然发现这些列不存在,然后尝试添加它们。然后抛出异常,“密钥已存在”。
UltraGridColumn 更改列,pctChgCol;
if (e.Layout.Bands[0].Columns.Contains("Change"))
{
changeColumn = e.Layout.Bands[0].Columns["Change"];
pctChgCol = e.Layout.Bands[0].Columns["Percent Change"];
}
else
{
changeColumn = e.Layout.Bands[0].Columns.Add("Change");
pctChgCol = e.Layout.Bands[0].Columns.Add("Percent Change");
}
changeColumn.Formula = "[Publish Price] - [Override Price]";
pctChgCol.Formula = "if(0=[Publish Price] , 0 , ([Publish Price] - [Override Price])/[Publish Price] )";
With the NetVantage Windows Forms 9.1 UltraGrid, I want to add some unbound columns to do some simple calculations. The first time this code is entered in the InitializeLayout delegate, it finds that the columns don't exist yet and then adds them. Suprisingly, when I get new data, rebind the grid, and then enter this delegate again, it still finds that these columns don't exist and then tries to add them. An exception is then thrown, "Key already exists."
UltraGridColumn changeColumn, pctChgCol;
if (e.Layout.Bands[0].Columns.Contains("Change"))
{
changeColumn = e.Layout.Bands[0].Columns["Change"];
pctChgCol = e.Layout.Bands[0].Columns["Percent Change"];
}
else
{
changeColumn = e.Layout.Bands[0].Columns.Add("Change");
pctChgCol = e.Layout.Bands[0].Columns.Add("Percent Change");
}
changeColumn.Formula = "[Publish Price] - [Override Price]";
pctChgCol.Formula = "if(0=[Publish Price] , 0 , ([Publish Price] - [Override Price])/[Publish Price] )";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个 RTFM。我应该调用不同的方法:
更改
为
这里的问题是 Contains 检查对象,而不是键。我正在检查列集合是否包含字符串对象。对于集合中具有该键的对象,Exists 返回 true。
This was an RTFM. I should have called a different method:
Change
to
The problem here is Contains checks for an object, not a key. I was checking to see if the columns collections contains a string object. Exists returns true of an object with that key is in the collection.