A有十二个复选框,用于过滤DataGridView中的数据。它们看起来或多或少是这样的:
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
filter1=CheckBox1.Checked
Do_Filter()
End Sub
我还有一个按钮“全部设置”:
Private Sub SetAll_Click(sender As Object, e As EventArgs) Handles SetAll.Click
CheckBox1.Checked = True
CheckBox2.Checked = True
' etc... 12 times
End Sub
一切正常。唯一的问题是Do_Filter()过程被调用了12次...任何想法如何推迟Do_Filter()调用并仅在SetAll_Click()结束时执行一次?
答案 0 :(得分:2)
您可以引入一个布尔变量:
Private doFilterEnabled As Boolean = True
在此处添加if语句:
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
filter1=CheckBox1.Checked
If doFilterEnabled Then
Do_Filter()
End If
End Sub
此处有小修正:
Private Sub SetAll_Click(sender As Object, e As EventArgs) Handles SetAll.Click
doFilterEnabled = False
CheckBox1.Checked = True
CheckBox2.Checked = True
' etc... 12 times
Do_Filter()
doFilterEnabled = True
End Sub