Winforms .NET DataRepeater - 未绑定的复选框不会在滚动时保持选中/未选中状态

发布于 2024-10-06 18:38:20 字数 373 浏览 0 评论 0原文

我有一个 WinForms 应用程序,它从数据库中检索项目并将其显示在列表中:

<Delete Button><Edit Button><Checkbox><PartNumber><PartDescription>

复选框未绑定,使用户能够选择列出的尽可能多的部分,然后编辑这些项目的属性。我遇到的问题是当我在运行时选择一个复选框时。我可以选择一个项目,然后快速向下滚动列表,突然间,许多其他项目的复选框被选中......似乎以随机方式。就好像当我滚动时,数据重复器正在触发复选框或其他东西上的事件。我不太确定。否则,复选框工作正常,并使用户能够正确选择项目,我只是不明白为什么随机选中/取消选中复选框。

I have a WinForms application that retrieves items from a database and displays them in a list:

<Delete Button><Edit Button><Checkbox><PartNumber><PartDescription>

The Checkbox is unbound and enables users to select as many of the parts listed and then edit properties on those items. The problem I am having is when I select a checkbox at runtime. I can select an item and then quickly scroll down the list and all of a sudden, many of the other items' checkboxes get checked...seemingly in a random fashion. It's as if when I scroll, the datarepeater is firing events on the checkboxes or something. I'm not really sure. The checkboxes work fine otherwise, and enable the user to select the item correctly, I just can't figure out why the random checking / unchecking of the checkboxes.

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

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

发布评论

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

评论(2

宛菡 2024-10-13 18:38:20

我认为这与 DataRepeaterItem 中的 CheckBox 控件不是数据绑定有关。所有其他字段都是,但复选框不是,所以当我上下滚动中继器时,复选框会丢失其状态。我目前正在重新设计我的类对象,以允许保留每个项目的“已检查”状态。

有人证实或否认这就是正在发生的事情吗?

谢谢!

I think it has to do with the CheckBox control in the DataRepeaterItem is not databound. All the other fields are, but the checkbox isn't so when I scroll up and down the Repeater, the checkboxes lose their state. I'm currently reworking my class object to allow the "Checked" state of each item to be preserved.

Anyone confirm or deny that this is what's happening?

Thanks!

九厘米的零° 2024-10-13 18:38:20

当我在设置绑定源之前设置中继器的数据源时,这种情况发生在我身上一次。我希望它能为您指明正确的方向。这是我的代码的摘录

    Dim sres As New frmSearchResults
    Dim dt As DataTable = resultsDataTable
    With sres
        .lblDate.DataBindings.Add(New Binding("Text", dt, "createtime", True))
        .lblOwner.DataBindings.Add(New Binding("Text", dt, "owner", True))
        .lblTicketNumber.DataBindings.Add(New Binding("Text", dt, "ticketnumber", True))
        .lblTitle.DataBindings.Add(New Binding("Text", dt, "tickettitle", True))
        .txtExcerpt.DataBindings.Add(New Binding("Text", dt, "excerpt", True))
        .btnLoad.DataBindings.Add(New Binding("Tag", dt, "ticketid", True))


        .dr1.DataSource = dt 'this used to come before my bindings above

        sres.Show()

    End With

this happened to me once when I set the repeater's data source before I setup the binding source. I hope it points you in the right direction. Here is an excerpt from my code

    Dim sres As New frmSearchResults
    Dim dt As DataTable = resultsDataTable
    With sres
        .lblDate.DataBindings.Add(New Binding("Text", dt, "createtime", True))
        .lblOwner.DataBindings.Add(New Binding("Text", dt, "owner", True))
        .lblTicketNumber.DataBindings.Add(New Binding("Text", dt, "ticketnumber", True))
        .lblTitle.DataBindings.Add(New Binding("Text", dt, "tickettitle", True))
        .txtExcerpt.DataBindings.Add(New Binding("Text", dt, "excerpt", True))
        .btnLoad.DataBindings.Add(New Binding("Tag", dt, "ticketid", True))


        .dr1.DataSource = dt 'this used to come before my bindings above

        sres.Show()

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