TreeView in Excel VBA

K

k.satish5

Is there any way to show the list that I have on a spreadsheet (see
image) on a TreeView Control using Excel VBA?

http://img135.imageshack.us/img135/6644/screenprintiv2.png

It is nothing but a list of folders gotten from somewhere using the
shell command and each folder put into 1 column of the Excel. I
basically want that structure to be shown on a User form with the
appropriate structure maintained...thought it may be possible using
Treeview? I have never used Treeview earlier, hence I have no idea how
to use it...any pointers will be greatly appreciated.

Thanks much!
Satish
 
S

Satish

Hi Andy

Thanks for the link...it was certainly very helpful. My requirement is
a bit different...but it will help me at least get started...Here is my
exact requirement:

I want the list of folders to be displayed to the user (which I think I
can work out from the sample example provided in your link)... But I
want something more...

I want the user to be able to delete/add/modify folders (nodes in this
case). Something like the explorer in Windows, where if a user deletes
a folder (node) all sub-folders (nodes within that node) must be
deleted...

Do let me know in case anyone has worked on something like this...
thanks for reading...

-Satish
 
A

Andy Pope

You just need to know which node is selected and then remove it.

Private Sub TreeView1_KeyDown(KeyCode As Integer, _
ByVal Shift As Integer)

Dim nodTemp As Node

If KeyCode = vbKeyDelete Then
Set nodTemp = TreeView1.SelectedItem
If MsgBox("Are you sure you want to delete " & _
nodTemp.Text, vbYesNo Or vbQuestion) = vbYes Then
TreeView1.Nodes.Remove nodTemp.Index
End If
End If

End Sub

Cheers
Andy
 
S

Satish

Thanx Andy!

Andy said:
You just need to know which node is selected and then remove it.

Private Sub TreeView1_KeyDown(KeyCode As Integer, _
ByVal Shift As Integer)

Dim nodTemp As Node

If KeyCode = vbKeyDelete Then
Set nodTemp = TreeView1.SelectedItem
If MsgBox("Are you sure you want to delete " & _
nodTemp.Text, vbYesNo Or vbQuestion) = vbYes Then
TreeView1.Nodes.Remove nodTemp.Index
End If
End If

End Sub

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top