Open text file from listbox

I’m trying to open a text file into a textarea from double clicking on a filename in a listbox. Any help appreciated.

Thank you…

Is the full path stored in the listbox cell or just the file name? If the path isn’t included is the path consistently always the same?

Yes, the full path and filename are in the listbox.

Here is one of many ways to accomplish what you asked for

// Assumes the DesktopListbox has a String property called FileNameSelected
// Adding the Event "SelectionChanged" creates the "Sub SelectionChanged() Handles SelectionChanged"
Sub SelectionChanged() Handles SelectionChanged
  FileNameSelected = Me.SelectedRowValue
End Sub

// Adding the Event "DoublePressed" creates the "Sub DoublePressed() Handles DoublePressed"
Sub DoublePressed() Handles DoublePressed
  // Listbox1 DoublePressed Event
  // Assumes all files being opened are in a common location
  // Assumes the common location is the desktop
  // Assumes the DesktopListbox has a String property called FileNameSelected
  // Assumes the project contains a TextArea control TextArea1
  Var f As FolderItem
  f = SpecialFolder.Desktop.Child(FileNameSelected)
  If f <> Nil And f.Exists Then
    Var input As TextInputStream
    input = TextInputStream.Open(f)
    TextArea1.Text = input.ReadAll
  End If
End Sub

1 Like

Just change the folderitem in my example to include the full path

Var f As New FolderItem(FileNameSelected, FolderItem.PathModes.Native)

That all worked very nicely. Thank you very much for the help.

1 Like