添加新的 DataRow 不会将行添加到 DataGridView

发布于 2024-12-01 04:45:45 字数 644 浏览 2 评论 0原文

在这个问题上我一直在用头撞墙,但一直没能让它发挥作用——所以我想我应该在这里问,以防万一事情很简单。

基本上,我有一个 DataGridView,我试图以编程方式向其中添加一行。

这是我正在使用的代码:

boundBookDataSet.LoadBoundBook.AddLoadBoundBookRow(
    null, null, null, null, null, DateTime.Now, null, null, null, 
    false, false, -1, null, -1, -1);

我还尝试在添加行后在 DataSet 以及新的 DataRow 上调用 AcceptChanges,并且还尝试在 DataGridView 上调用 Refresh。

不管怎样,无论我做什么,我最终都会得到boundBookDataSet.LoadBoundBook.Count==70和loadBoundBookBindingSource.Count==69。我的 DataGridView 不会拾取新行,因为它没有反映在绑定源中(至少这是我的猜测)。

可悲的是,这是有效的 - 但我做了一个巨大的改变,但不知道是什么破坏了它。损坏的代码根本没有改变...

如果有人知道如何解决这个问题,我将非常感谢您的帮助。

I have been beating my head against the wall on this one and I haven't been able to get it working - so I figured I'd ask here just in case it's something simple.

Basically, I have a DataGridView and I'm trying to add a row to it programatically.

Here is the code I'm using:

boundBookDataSet.LoadBoundBook.AddLoadBoundBookRow(
    null, null, null, null, null, DateTime.Now, null, null, null, 
    false, false, -1, null, -1, -1);

I've also tried calling AcceptChanges on both the DataSet as well as the new DataRow after adding the row, and I've also tried calling Refresh on the DataGridView.

Anyway, no matter what I do, I end up with boundBookDataSet.LoadBoundBook.Count==70 and loadBoundBookBindingSource.Count==69. My DataGridView won't pick up the new row since it isn't reflected in the binding source (at least that's my guess).

Sadly, this was working - but I made a huge change and can't figure out what broke it. The code that is broken didn't change at all...

If anyone has any idea how to resolve this, I would seriously appreciate the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

浸婚纱 2024-12-08 04:45:45

啊哈!我想通了。 :)

当我再次查看 BindingSource 中的字段时,我意识到我已经设置了 Filter 字段。如果我删除过滤器,则 loadBoundBookBindingSource.Count 会正确递增,并且 DataGridView 会拾取新记录。

基本上,看起来我需要清除过滤器,添加记录,然后再次设置过滤器。

Aha! I figured it out. :)

As I was looking through the fields in my BindingSource once again, I realized I had the Filter field set. If I remove the filter, the loadBoundBookBindingSource.Count gets incremented correctly and the DataGridView picks up the new record.

Basically, it looks like I need to clear the filter, add the record, then set the filter again.

梦在深巷 2024-12-08 04:45:45

假设它的winforms您谈论的问题的答案可以在这个线程上找到: http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/f12158b3-4510-47cb-b152-409489c3a51a/

Assuming its winforms your talking about an answer to the problem is available on this thread: http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/f12158b3-4510-47cb-b152-409489c3a51a/

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