Hi,
I am trying to populate a popupmenu with the contents of a folder (which will be files only, no subfolders).
I also need the user to be able to double click on the items in the list, and have them open in the default application.
I have been away from Xojo for so long, I have forgotten almost everything
This is for a Windows 10 app.
Does anyone know of any examples of this, which I can then study in order to re-learn from.
All I have so far is:
[code]Dim f as folderitem
f = GetFolderItem(âC:\Users\Richard\Desktop\Miscellaneousâ)
For i As Integer = 0 To f.Count -1
TestPopupMenu.AddRow(f.Item(i).Name)
Next[/code]
And even this doesnât populate the popupmenu.
Struggling big time - cant believe I have forgotten everything
FolderItem.Count and FolderItem.Item are 1-based, so that could be causing you an issue with a directory with one item in it.
Try this:
dim fTarget as FolderItem = SelectFolder
// user cancelled
if fTarget = nil then return
// FolderItem.Count is very intense and should not be used in a for loop.
dim iCount as Integer = fTarget.Count
for i as Integer = 1 to iCount
dim fThis as FolderItem = fTarget.Item(i)
// Folderitem error, let's not get a NOE
if fThis = nil then continue
TestPopupMenu.AddRow(fThis.DisplayName)
next
{Code written in post editor disclaimer}
Also, in the time that youâve been gone the way you access files on disk has gotten stricter. Now is the best time to start pretending GetFolderItem doesnât exist if youâre learning again!
Tim, if I need to forget about GetFolderItem as you recommended, does this mean it is becoming deprecated? as it is currently still in the language reference?
Also, how do I avoid making the usser select a folder, and instead hardcode a specific folder?
Basically, how do I hardcode the following path, without using GetFolderItem?
f = GetFolderItem(âC:\Users\Richard\Desktop\Miscellaneousâ)
I cant see anything appropriate in the clasic language reference which would replace it
Apologies, probably the way I explained it
I need the file to open when the user selects the file from the popup menu, not when they double click it. Sorry, been a very long day
This code is in a method to populate the popupmenu:
[code]// POPULATE HUMAN RESOURCES POPUP MENU
// DEFINE THE TARGET FOLDER
dim fTarget as FolderItem = GetFolderItem(âC:\Users\Richard\Desktop\Test\HumanResourcesâ)
// PREVENT ERROR IF FOLDER HAS BEEN DELETED
If fTarget <> Nil And fTarget.Exists and fTarget.Directory Then
// COUNT FILES IN FOLDER
dim iCount as Integer = fTarget.Count
// LOOP THROUGH FOLDER ITEMS
for i as Integer = 1 to iCount
dim fThis as FolderItem = fTarget.Item(i)
// ASSIGN FILE PATH TO ROWTAG
RowTag(i) = fThis.GetSaveInfo(GetFolderItem(""))
// PREVENT AN ERROR IF FOLDER CONTAINS NO FILES
if fThis = nil then continue
// POPULATE THE ACTUAL POPUP MENU
HumanResourcesPopupMenu.AddRow(fThis.DisplayName)
next
End[/code]
However, I get an error stating that the item RowTag does not exist, but popultes the popupmenu fine if I remove that line of code.
In the popupmenuâs change event I have the following code which I need to launch the selected item in the list:
[code]// OPEN SELECTED FILE
If Me.ListIndex >= 0 Then
Dim FileToOpen As FolderItem
Dim f As New FolderItem
FileToOpen = f.GetRelative(RowTag(Me.ListIndex))
If FileToOpen <> Nil And FileToOpen.Exists Then
FileToOpen.Launch
End If
End If[/code]
This also states that the item RowTag does not exist
Can anyone assist, as my head is now confused.