0
ListBox
にはフルパス、ToolStripMenu
には[ファイルを開く]または[ファイルをフォルダに表示]があります。ListBoxを右クリックしてアイテムを選択しないでください
問題は次のとおりです。ListBoxItem
を左クリックしてから、右クリックして表示する必要があるファイルを選択してください。
私がこれをしないと、項目が選択されていないので、NullReferenceException
が得られます。
右クリックした項目を選択するにはどうすればよいですか?以下のコードは動作しませんが、エラーを与え、私にドキュメントフォルダが表示されないのはなぜ...
Private Sub ShowInFolderToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ShowInFolderToolStripMenuItem.Click
Try
If DirectCast(DirectCast(sender, ToolStripMenuItem).GetCurrentParent, _
ContextMenuStrip).SourceControl.GetType Is GetType(ListBox) Then
Shell("explorer /select, " & DirectCast(DirectCast(DirectCast(sender, _
ToolStripMenuItem).GetCurrentParent, ContextMenuStrip).SourceControl, _
ListBox).SelectedItem.ToString, AppWinStyle.NormalFocus)
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
ちょうど別の質問:
は、ここに私のコードですか?
Private Sub ListBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseDown
Try
DirectCast(sender, ListBox).SelectedIndex = DirectCast(sender, ListBox).IndexFromPoint(e.X, e.Y)
Catch ex As Exception
End Try
End Sub
@Plutonixはい、私はこれを知って開始 – Plutonix
で選択した項目があるかどうかをチェックできます。
– genespos@Plutonix私は解決しましたが、私はまだより良い解決策にオープンしています;) – genespos