无法选择数据绑定的 DataGridView 中的复选框
我有一个运行良好的 DataGridView。我用它只是为了显示数据。
现在,我希望能够通过复选框选择行,并通过单击按钮仅对选定的行执行操作(此按钮在同一表单上的网格之外)。 为此,我遵循 这些步骤将复选框列添加到 datagridview。
运行应用程序时看到的是我无法通过鼠标单击或键盘选中该复选框。从它的外观我可以理解它不处于禁用/只读状态。因此,每当我尝试单击该复选框时,它都会像启用的复选框一样正常更改其边框。但最终它没有选中复选框。
I've a DataGridView which is working perfectly fine. I use it just to show data.
Now I want ability to select rows by check box and perform an operation for only selected rows on click of a button (this button is out of the grid on the same form).
For this purpose, I'm following these steps to add checkbox column to datagridview.
On running the application what is see is I can't check the check box either by mouse click or keyboard. And by its looks I can understand that its not in disabled/readonly state. So whenever I try to click on the checkbox, it changes it's borders normally as an enabled check box does. But finally it is not checking the check box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试一下。
可能会帮助你。
Ismail 这是您的困惑的解决方案Dgv-DatabindingCompleteEvent
Try it.
may help you.
Ismail here is your solution of your confusion Dgv-DatabindingCompleteEvent
我遇到了同样的问题。对我来说,解决方案非常简单。我的 datagridview 有一个禁用的编辑选项(因为我不希望用户更改数据),并且我希望能够选中/取消选中我的 DataGridViewCheckBoxColumn。因此,在 dataGridView 属性中,我选中了“启用编辑”选项,但在代码中,我已为除我所需的 checkBoxColumn 之外的每一列禁用它。
希望它会对某人有所帮助。
I went through the same problem. For me the solution was pretty simple. My datagridview had a disabled editing option (because I didn't want the user to change the data) and I wanted to be able to check/uncheck my DataGridViewCheckBoxColumn. So in the dataGridView properties I checked the 'Enable Editing' option, but in the code I've disabled it for every column except of mine desired checkBoxColumn.
Hope it will help to somebody.
如果你想检查 dgv 中所有复选框的状态:
if you want to check the state of all checkBoxes in the dgv:
就我而言,我在 page_load 中有 gridview 加载代码,因此单击按钮后,网格会重新加载并丢失其选择。所以将代码移到里面
对我有用。
在page_load中放置一个断点以便更好地理解。
In my case I had the gridview loading code in page_load, so after a button click the grid was reloading and lost its selection. So Moving the code inside
worked for me.
Put a breakpoint in page_load to understand better.