我需要在 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)的。
