Datagridview复选框列验证
在DatagridView中,我有数据绑定复选框列。但是,如果我选中或取消选中多个复选框,则并非所有更改都会保存。 (它不会全部触发属性 Set 方法,也许每隔两个触发一次)。但是,如果我在每个复选框单击后,单击下一个复选框之前的另一个单元格(列),则所有操作都将触发 Set 方法。因此,单元格验证似乎不是在每个单元格的基础上工作,而是在每列的基础上工作(对于复选框列)。那么如何解决这个问题呢?
In a DatagridView I have databound checkboxcolumns. But if I check or uncheck multiple checkboxes, not all changes are saved. (It doesn't trigger the property Set method on all, maybe on every 2nd). However if I after each checkbox-click, click on another cell (column) before the next checkbox, then all actions will trigger the Set methods. So it seems the cell validation does not work on a per-cell basis, but on a per column basis (For the checkboxcolumn). So how do you solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到答案: DataGridView with CheckBox cell Problem
但可能更简单的替代方法是放入保存按钮方法:
Found the answer: DataGridView with CheckBox cell problem
But probably easier alternative is to put in the save button method:
目前还不清楚您尝试了什么以及什么不起作用。我假设您有一个 Winform 应用程序并使用 SqlDataSource 将 SQL-Server 表绑定到网格。数据库中有一个布尔(位)字段,因此网格会自动生成一个 DataGridViewCheckBoxColumn。您试图保存用户单击保存按钮时所做的所有更改。
这些猜测都正确吗?
您所要做的就是使用数据适配器更新数据集/数据表。
MSD-示例: http://msdn.microsoft.com/en-use/library /fbk67b6z.aspx
如果应将更改直接保存到数据库,您可以处理 BindingSource 的 CurrentItemChanged 事件。
It is not really clear what you have tried and what doesn't work. I assume you have a Winform application and use a SqlDataSource to bind a SQL-Server table to your grid. There is a boolean(bit) field in your database, hence the grid automatically generates a DataGridViewCheckBoxColumn. You are trying to save all changes that the user has made when he clicks a save-button.
Are all of these guesses correct?
All you have to do is to update your dataset/datatable with the dataadapter.
MSD-Example: http://msdn.microsoft.com/en-use/library/fbk67b6z.aspx
If changes should be saved directly to the database, you can handle the CurrentItemChanged-event of the BindingSource.