[英]Datagridview: how to commit checkbox and and immediately filter by it?
I have a datagridview DataGridView1, bound to a DataTable1BindingSource, with the only writable cell being a checkbox bound to the boolean column "IsSelected". 我有一个绑定到DataTable1BindingSource的datagridview DataGridView1,唯一可写的单元格是绑定到布尔列“ IsSelected”的复选框。 As soon as the user checks the checkbox, I want to show only the row where the checkbox is checked. 用户选中该复选框后,我只想显示选中该复选框的行。 So i put the following code: 所以我把下面的代码:
Private Sub DataGridView1_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
DataGridView1.EndEdit()
DataTable1BindingSource.Filter = "IsSelected"
End Sub
But it does not work - once the ckeckbox is checked, the datagridview does not show any rows at all. 但这是行不通的-一旦选中了ckeckbox,datagridview根本不会显示任何行。
If I move the statement DataTable1BindingSource.Filter = "IsSelected" to a separate command button, 如果将语句DataTable1BindingSource.Filter =“ IsSelected”移动到单独的命令按钮,
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DataTable1BindingSource.Filter = "IsSelected"
End Sub
then upon editing the checkbox and then clicking the button, it works as expected, ie shows only this row. 然后在编辑复选框并单击按钮后,它会按预期工作,即仅显示此行。
Why it does not work when it's issued immediately? 为什么当它立即发布时不起作用?
Found the reason. 找到了原因。 After 后
Sender.EndEdit
, before applying the filter, have to also issue ,在应用过滤器之前,还必须发出
DataTable1BindingSource.EndEdit
Then it all works as expected. 然后一切都按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.