XtraGrid 无法正确显示新添加的行
我正在使用 DevExpress 2.9.5 的 XtraGrid 来显示动态行集的记事本。记事本被集成到另一个应用程序中,这就是为什么它必须基于 UserControl 类并实现几个自定义接口。
public partial class BlotterForm : UserControl, ISMMdiEmbeddable, ISMAssociatedMFCWindow
{
private BindingList<BlotterTrade> fDeals;
....
}
由于使用 BindedList 将数据绑定到控件,因此任何更改都应自动反映在表单中。如果我尝试向 fDeals 添加新行,如下所示:
public void AddDeal()
{
fDeals.Add(new BlotterTrade(1,2,3));
}
...我可以看到该行,但它的内容是垃圾。
我尝试在一个小型测试应用程序中执行相同的操作。它工作正常,唯一的区别是测试应用程序中的记事本基于 DevExpress.XtraEditors.XtraForm。对我来说,现在看来原始记事本的形式不会重载某些方法或错过某些事件。但我无法找出到底错过了什么。
有人可以告诉我我做错了什么或不做什么吗?
谢谢。
I'm using XtraGrid of DevExpress 2.9.5 to display a blotter of dynamic set of lines. The blotter is integrated into another application, this is why it has to be based on UserControl class and also implement a couple of custom interfaces.
public partial class BlotterForm : UserControl, ISMMdiEmbeddable, ISMAssociatedMFCWindow
{
private BindingList<BlotterTrade> fDeals;
....
}
As the data is binded to control using BindedList, any change should be reflected in the form automatically. And if I try to add new line to fDeals like follows:
public void AddDeal()
{
fDeals.Add(new BlotterTrade(1,2,3));
}
... i can see the line, but it's content is rubbish.
I tried to do the same in a small test application. It works ok with only difference that the blotter in test application is based on DevExpress.XtraEditors.XtraForm. To me it looks now that the form of original blotter doesn't overload some method or miss some event. But I cannot find out what exactly is missed.
Can somebody tell me what I do wrong or don't do?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几点:
BindingList 并不总是能很好地与 DevExpress 配合使用,建议改用 XPCollection。
您是否有关于如何在 xtragrid 中设置列的更多信息?如果您在列中使用了不正确的字段名称,那么它们将不会显示您要查找的内容。
如果您使用的参数(1、2、3)是作为 fkey 存储到其他对象的 id(不确定您是否使用 xpo),那么它们也不会正确显示(会有可能是单元格中的“+”而不是任何值)。
[aside] 确保 blottertrade 实现 INotifyPropertyChanged,以便更好地与网格交互。
A couple of things:
BindingList doesn't always work too well with DevExpress, and it's suggested to use XPCollection instead.
Do you have any more info about how you setup your columns in the xtragrid? If you use incorrect field names in the column, then they won't show what you're looking for.
If the params you're using (1, 2, 3) are ids stored as fkeys to other objects (not sure if you're using xpo or not) then they won't show up correctly either (there'll likely be a '+' in the cell instead of any values).
[aside] be sure that blottertrade implements INotifyPropertyChanged for better interaction with the grid.
感谢大家的回答和评论。我想我解决了这个问题。它实际上与我的应用程序中本机 C++ 和 C# 层之间的交互有关。本来应该在XtraGrid中显示的对象是在C++层中创建的,网格的显示与对象构造/解构是异步的,这就是为什么当网格准备好显示它时,对象本身并不存在。于是就有了垃圾。幸好网格本身没有崩溃或引发异常。
Thanks to everybody for the answers and comments. I think I sorted out the problem. It was actually related to interaction between native C++ and C# layers in my application. The object that was supposed to be displayed in XtraGrid was created in C++ layer, the grid was displayed asynchronously with object construction/deconstruction, that's why at the moment when the grid was ready to display it, the object itself didn't exist. Hence the rubbish. It's good the grid itself was not crashing or firing exceptions.