[RESOLVED] Add nodes treeview drag-drop textfile
Hi,
I have a simple textfile which I want to drag-drop into the treeview. After the drop read the textfile (line by line) and create the nodes. There are no subnodes (what-so-ever). File looks like this:
line1
line2
line3
line4
Any suggestions/examples?
Re: Add nodes treeview drag-drop textfile
Re: Add nodes treeview drag-drop textfile
If it were that simple I wouldn't ask. Besides that, I probably need to Peek(). How to add the nodes according the textfile?
Re: Add nodes treeview drag-drop textfile
try this:
vb Code:
Public Class Form1
Private Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim file As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String()).First
Dim lines() As String = IO.File.ReadAllLines(file)
For Each line As String In lines
TreeView1.Nodes.Add(line, line)
Next
End If
End Sub
Private Sub TreeView1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TreeView1.AllowDrop = True
End Sub
End Class
Re: Add nodes treeview drag-drop textfile
Thanks Paul. +REP deserved, but I can't give you at the moment unfortunately.
Re: [RESOLVED] Add nodes treeview drag-drop textfile