Results 1 to 6 of 6

Thread: [RESOLVED] Add nodes treeview drag-drop textfile

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [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?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: Add nodes treeview drag-drop textfile

    Combination of these two should cover it:

    Drag and drop with treeview: http://www.codeproject.com/Articles/...nd-Drop-VB-NET

    Read and write with text files: http://www.techrepublic.com/article/...ic-net/1045309
    Rico

    Using: VB.net & MS SQL

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    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?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Add nodes treeview drag-drop textfile

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
    4.         If e.Data.GetDataPresent(DataFormats.FileDrop) Then
    5.             Dim file As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String()).First
    6.             Dim lines() As String = IO.File.ReadAllLines(file)
    7.  
    8.             For Each line As String In lines
    9.                 TreeView1.Nodes.Add(line, line)
    10.             Next
    11.  
    12.         End If
    13.     End Sub
    14.  
    15.     Private Sub TreeView1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver
    16.         If e.Data.GetDataPresent(DataFormats.FileDrop) Then
    17.             e.Effect = DragDropEffects.All
    18.         End If
    19.     End Sub
    20.  
    21.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    22.         TreeView1.AllowDrop = True
    23.     End Sub
    24.  
    25. End Class

  5. #5

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Add nodes treeview drag-drop textfile

    Thanks Paul. +REP deserved, but I can't give you at the moment unfortunately.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] Add nodes treeview drag-drop textfile

    no problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width