我相信这很容易,但我现在遇到了这个问题。我有一个列表视图,每次单击一个项目时,我都会将其名称存储在一个字符串变量中。发生的情况是,当我单击列表视图上的一个项目,然后再次单击列表视图内部而不选择任何项目时,它不会失去焦点并将前一个选定项目的名称存储在字符串变量中。我想要发生的是,每次我单击一个项目,然后单击列表视图内部或外部而不选择任何项目时,它必须失去焦点并且不将项目名称存储在字符串变量中。
Private Sub lvReceivedFiles_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles lvReceivedFiles.MouseClick
If e.Button = Windows.Forms.MouseButtons.Left Then
If lvRecievedFiles.FocusedItem.Selected = True
lvReceivedFiles.FullRowSelect = True
'When an item is clicked in the list view, store its name.
fName = "\" & Path.GetFileName(lvReceivedFiles.FocusedItem.Text)
Else
'This part here doesn't make any sense because it doesn't execute
'every time I click in the list view without selecting any item.
'ListView.FocusedItem.Selected is always true.
End If
End If
End Sub