确定是否在列表视图框中选择了某个项目
使用 VB.net 2010 我试图弄清楚是否选择了某个项目。原因是,如果用户单击某个项目并按下按钮,那么一切都会正常工作。但是,如果用户选择一个项目,然后单击列表视图底部的空白点,然后单击按钮,则会崩溃。
我的代码是这样的:
If (lstMaster.SelectedItems(0).SubItems(1).Text) Is Nothing Then
MsgBox("test")
End If
任何帮助都会很棒! :o)
大卫
Using VB.net 2010 i am trying to figure out if an item was selected or not. Reason being is that if the user clicks on an item and pushes a button then everything works just fine. However, if the user selects an item and then clicks on a blank spot on the bottom of the listview and then clicks the button then it crashes.
My code is this:
If (lstMaster.SelectedItems(0).SubItems(1).Text) Is Nothing Then
MsgBox("test")
End If
Any help would be great! :o)
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通过检查
SelectedItems
不为空,确保首先选择某些内容。Ensure that something is selected first by checking that
SelectedItems
is not empty.检查
lstMaster.SelectedItems(0)。
已选择
check
lstMaster.SelectedItems(0).
Selected
不确定我是否理解正确 - 尝试使用 ListView MouseMove 事件并检查 lstMaster.SelectedItems.Count > 0 如果要根据 ListView 控件中是否已选择行来更改 Button 的 Enable 属性。
Not sure if I've understood you correctly - Try using the ListView MouseMove event and check that lstMaster.SelectedItems.Count > 0 if you want to change the Enable property of a Button based on whether a row has been selected or not within your ListView control.
将此检查与“If/EndIf”结构结合使用:
ListView1.Items(0).Selected = True
Use this checking with "If/EndIf" construction:
ListView1.Items(0).Selected = True