XtraGrid 无法正确显示新添加的行

发布于 2024-08-07 02:02:34 字数 659 浏览 9 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

层林尽染 2024-08-14 02:02:34

有几点:

  1. BindingList 并不总是能很好地与 DevExpress 配合使用,建议改用 XPCollection。

  2. 您是否有关于如何在 xtragrid 中设置列​​的更多信息?如果您在列中使用了不正确的字段名称,那么它们将不会显示您要查找的内容。

  3. 如果您使用的参数(1、2、3)是作为 fkey 存储到其他对象的 id(不确定您是否使用 xpo),那么它们也不会正确显示(会有可能是单元格中的“+”而不是任何值)。

  4. [aside] 确保 blottertrade 实现 INotifyPropertyChanged,以便更好地与网格交互。

A couple of things:

  1. BindingList doesn't always work too well with DevExpress, and it's suggested to use XPCollection instead.

  2. 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.

  3. 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).

  4. [aside] be sure that blottertrade implements INotifyPropertyChanged for better interaction with the grid.

乖不如嘢 2024-08-14 02:02:34

感谢大家的回答和评论。我想我解决了这个问题。它实际上与我的应用程序中本机 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文