gpt4 book ai didi

c# - 需要在 Winform 应用程序中添加 DataGridViewCheckBoxColumn

转载 作者:太空宇宙 更新时间:2023-11-03 22:18:28 24 4
gpt4 key购买 nike

我需要在 DataGridView 中针对每一行放置一个复选框。为此,我正在使用 DataGridViewCheckBoxColumn。但是在这里用户可以选择多于 1 行。如何限制用户在 DataGridView 中选择多行?

最佳答案

选中该复选框后,您将必须自己完成。

If you want to respond immediately when users click a check box cell, you can handle the DataGridView.CellContentClick event, but this event occurs before the cell value is updated. If you need the new value at the time of the click, one option is to calculate what the expected value will be based on the current value. Another approach is to commit the change immediately, and handle the DataGridView.CellValueChanged event to respond to it. To commit the change when the cell is clicked, you must handle the DataGridView.CurrentCellDirtyStateChanged event. In the handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.

无论您使用哪种方法,当您处理被选中的复选框时,您都需要将所有其他复选框标记为未选中。你将如何做到这一点取决于你的 DataGridView 是否(以及如何)是数据绑定(bind)的。

关于c# - 需要在 Winform 应用程序中添加 DataGridViewCheckBoxColumn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4144181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com