Dim count As Func(Of Integer, Boolean) = Function(x As Integer) x = 1
If (count(GetSelectedCount())) Then
'Proceed
Else
MessageBox.Show("You can only select one item at a time.", "Multiple items selected", MessageBoxButtons.OK)
End If
GetSelectedCount返回网格中checkemarked项的数量。当没有选择任何东西时它返回0。只有在选择1个项目时,Lambda才会返回true。只有当选择> 1项目时,消息框才应该运行。即使在没有选择任何项目的情况下,我也可以获取消息框。这个Lambda的处理是什么?
解决〜决定放弃Lambda和去老同学
Select Case GetSelectedCount()
Case 1
Case Is > 1
MessageBox.Show("You can only select one item at a time.", "Multiple Selection", MessageBoxButtons.OK)
Case Else
MessageBox.Show("You have no items selected.", "No Selection", MessageBoxButtons.OK)
End Select
Na,用“预计表达”加下划线的蓝色。 – 2009-01-27 22:01:18