0

I have a program that lists files found from a search, and when the user selects one of the files and clicks open, it will open the file they've selected. I only want them to be able to open one file at a time, and I want an error box to show if they click Open without selecting a file...does anyone know what error I can use or what kind of conditioning I can use to make this happen? This is what I have:

Private Sub OpenBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenBtn.Click
        Try
            For Each file As ListViewItem In FilesList.Items
                Dim filePath As String = file.SubItems(1).Text & "\" & file.Text
                If file.Selected = True Then
                    Process.Start(filePath)
                End If
            Next
        Catch ex1 As System.ComponentModel.Win32Exception
            MessageBox.Show("Unable to identify a program with which to open this file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
          End Try
    End Sub
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by selvaganapathy
0

Hi, Use ListView1.SelectedItems instead of ListView1.Items. If ListView1.SelectedItems.Count =0 then There is nothing selected otherwise something selected.

If you want the user should select only one then Change MultiSelect Property to False.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.