简体   繁体   English

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

[英]Need to add DataGridViewCheckBoxColumn in a Winform Application

I need to put a Checkbox against each Row in a DataGridView. 我需要在DataGridView中为每一行放置一个Checkbox。 I am making use of DataGridViewCheckBoxColumn for the purpose. 我正在使用DataGridViewCheckBoxColumn来实现此目的。 But here user is able to select more than 1 row. 但是这里用户可以选择超过1行。 How to restrict the user from selecting multiple rows in a DataGridView? 如何限制用户在DataGridView中选择多行?

You will have to do it yourself when the checkbox is checked. 选中复选框后,您必须自己完成。

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. 如果要在用户单击复选框单元格时立即响应,则可以处理DataGridView.CellContentClick事件,但此事件在更新单元格值之前发生。 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. 另一种方法是立即提交更改,并处理DataGridView.CellValueChanged事件以响应它。 To commit the change when the cell is clicked, you must handle the DataGridView.CurrentCellDirtyStateChanged event. 要在单击单元格时提交更改,您必须处理DataGridView.CurrentCellDirtyStateChanged事件。 In the handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value. 在处理程序中,如果当前单元格是复选框单元格,则调用DataGridView.CommitEdit方法并传入Commit值。

Whichever method you use, when you handle the checkbox being checked, you will need to mark all the other checkboxes as unchecked. 无论使用哪种方法,当您处理选中的复选框时,您都需要将所有其他复选框标记为未选中。 How you will do that depends on whether (and how) your DataGridView is data-bound. 您将如何做到这一点取决于您的DataGridView是否(以及如何)受数据限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WinForm应用程序:无法设置DataGridViewCheckBoxColumn的默认值 - WinForm app: Cannot set default values of a DataGridViewCheckBoxColumn 将HTML区域添加到Winform应用程序 - Add an HTML area to a Winform Application 如何在DatagridviewCheckBoxColumn的Header添加复选框控件? - How to add checkbox control at the Header of DatagridviewCheckBoxColumn? 如何在Winform应用程序中添加Windows 7视觉样式? - How to Add Windows 7 visual style in winform application? 将Web前端添加到Winform应用程序 - Add a web front end to a winform application 在winform应用程序的数据网格视图中添加上下文菜单 - Add context menu in a datagrid view in a winform application 如何添加winform c#应用程序的帮助 - How to add help to winform c# application 需要在Winform应用程序的DataGrid视图中对每一行放置一个RadioButton - Need to put a RadioButton against each Row in a DataGrid view in a Winform Application 使用 DotNetcore 6 winform 应用程序构建的应用程序需要 DotNet Desktop 运行时 - App build using DotNetcore 6 winform application need DotNet Desktop runtime Datagridview使用以下方法在某些单元格上添加复选框 <DataGridViewCheckBoxColumn> ,而不是专栏 - Datagridview add Checkbox on some cell using <DataGridViewCheckBoxColumn>, not a column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM