禁用连接到列表框的按钮

时间:2014-07-25 15:39:37

标签: vb.net

我有一个列表框,当没有项目时我想要按钮不启用。这是我目前的代码

If lstMarks.Items.Count = -1 Then btnShowMean.Enabled = False End If

但即使列表框中没有任何内容,您仍然可以按下按钮。解决此问题的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

计数永远不会小于零:

If lstMarks.Items.Count = 0 Then
  btnShowMean.Enabled = False
End If

或只是:

btnShowMean.Enabled = (lstMarks.Items.Count > 0)