I want my to create an explorer like application. What control should i use to show the contents of a directory.
I tried listview and listbox. Unfortunately i was unable to add items in a listview using the function getdirectories("D:\")
I managed to do so with listbox control. But how can i distinguish whether the selected entry is a file or a directory. Code snippet is given below :

Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        [B]sel = ListBox1.SelectedItem[/B]
            ListBox1.Items.Clear()
            ListBox1.Items.AddRange(System.IO.Directory.GetDirectories(sel))
            ListBox1.Items.AddRange(System.IO.Directory.GetFiles(sel))
    End Sub

I want that if the sel is file, then it'll be open in its default application,i.e. using system.process.start(sel.filetype).
Else if sel is a directory then the directory will open.

Recommended Answers

All 2 Replies

The listbox selected item is always an object.

You can use the TypeOf operator to verify if it is a FileInfo or a DirectoryInfo class object, then act according.

Hope this helps

Thanks LOLA, it's such a great of you to help me. But i've managed to do so.
Actually i saved all the filenames of the opening directory in an array...and then check if the name is in array.

files = System.IO.Directory.GetFiles([I]currentDirectory[/I])
if files.contains(listbox1.selecteditem) then
system.diagnostics.process.start(listbox1.selecteditem)
endif

The listbox selected item is always an object.

You can use the TypeOf operator to verify if it is a FileInfo or a DirectoryInfo class object, then act according.

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.