Question[Help]Drag & Drop?

Posts 1–15 of 36 · Page 1 of 3
[Help]Drag & Drop?
Now I need drag and drop for .txt and .rtf files...


So you can just drag and drop, It not in the forums anywhere. but its a request for Notes 3.0

(For the record, this is only time Ive asked for help for the Notes collection so yeah...)
Textbox example:

(Set AllowDrop property to true)

[php] Private Sub TextBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim MyFiles() As String

MyFiles = e.Data.GetData(DataFormats.FileDrop)
For i = 0 To MyFiles.Length - 1
Msgbox(MyFiles(i))
next

End If

End Sub

Private Sub TextBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub[/php]
That just shows the file location....I got it out of the msg box and still only inputs file location..
Quote Originally Posted by Web-Designer View Post
That just shows the file location....I got it out of the msg box and still only inputs file location..
Well you need to read through that file, you got the path now
As Kevin said, you can just read the file. Something like this:

[php]
Private Sub TextBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
For Each file As String In e.Data.GetData(DataFormats.FileDrop)
TextBox1.Text = String.Concat(TextBox1.Text, IO.File.ReadAllText(file), ControlChars.CrLf)
Next
End If
End Sub

Private Sub TextBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
For Each s As String In e.Data.GetData(DataFormats.FileDrop)
If Not System.Text.RegularExpressions.Regex.Match(IO.Path .GetExtension(s), "(.txt|.rtf|.doc|.xml)").Success Then
TextBox1.AllowDrop = False
Exit For
End If
Next
TextBox1.AllowDrop = True
e.Effect = DragDropEffects.All
End If
End Sub
[/php]

There j00 go.
Quote Originally Posted by Jason View Post
As Kevin said, you can just read the file. Something like this:

[php]
Private Sub TextBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
For Each file As String In e.Data.GetData(DataFormats.FileDrop)
TextBox1.Text = String.Concat(TextBox1.Text, IO.File.ReadAllText(file), ControlChars.CrLf)
Next
End If
End Sub

Private Sub TextBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
For Each s As String In e.Data.GetData(DataFormats.FileDrop)
If Not System.Text.RegularExpressions.Regex.Match(IO.Path .GetExtension(s), "(.txt|.rtf|.doc|.xml)").Success Then
TextBox1.AllowDrop = False
Exit For
End If
Next
TextBox1.AllowDrop = True
e.Effect = DragDropEffects.All
End If
End Sub
[/php]

There j00 go.
That code isn't working ether...so yeah.

I don't think drag and drop is a big deal anyways, its not a tab notepad anyways! So np, I'd like it but I'm not gonna waste more time trying to get it to work for it (unless I'm sure it'll work for sure.)
Quote Originally Posted by Web-Designer View Post


That code isn't working ether...so yeah.

I don't think drag and drop is a big deal anyways, its not a tab notepad anyways! So np, I'd like it but I'm not gonna waste more time trying to get it to work for it (unless I'm sure it'll work for sure.)
Worked for me fine haha. Sure your file extension was valid for the Regular Expression?
how about you tell me exactly what you are trying to do ? Drag and drop text? Components? I missed alot this past week. Catch me up.
I think he's trying to drag and drop a .txt file onto a textbox and display the contents in said textbox.
why make a notepad if your not a begginer. Use notepad ++
Well, in that case. Jasons & Kevin solution is accurate. And is on MSDN , but there is something that isn't on MSDN that everyone missed

this is what happens when everyone copies and pastes from MSDN or from a member here, they miss the little things that are VERY important

Source (as Jason & kevin said)

Code:
 Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
Code:
 Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim MyFiles() As String
            MyFiles = e.Data.GetData(DataFormats.FileDrop)
            TextBox1.Text = My.Computer.FileSystem.ReadAllText(MyFiles(0))
        End If
    End Sub
What everyone missed which is VERY important to this whole thing


Code:
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.AllowDrop = True
    End Sub
If a form or object is not set to allowdrop then you can write 100 pages of code and it won't work

Quote Originally Posted by NextGen1 View Post
Well, in that case. Jasons & Kevin solution is accurate. And is on MSDN , but there is something that isn't on MSDN that everyone missed

this is what happens when everyone copies and pastes from MSDN or from a member here, they miss the little things that are VERY important

Source (as Jason said)

Code:
 Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
Code:
 Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim MyFiles() As String
            MyFiles = e.Data.GetData(DataFormats.FileDrop)
            TextBox1.Text = My.Computer.FileSystem.ReadAllText(MyFiles(0))
        End If
    End Sub
What everyone missed which is VERY important to this whole thing


Code:
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.AllowDrop = True
    End Sub
If a form or object is not set to allowdrop then you can write 100 pages of code and it won't work

I said that
Oh yeah you did, didn't see it, but I bet it was overlooked, and jason didn't say that, plus even though it's a properly , runtime is the best bet , and giving the code may allow them to realize it, when someone see's code a lot of time they C&P and don't read the text prior. I din't even see it because I meticulously read over your code, so I didn't see it because I myself didn't read the preceding text
Quote Originally Posted by NextGen1 View Post
Oh yeah you did, didn't see it, but I bet it was overlooked, and jason didn't say that, plus even though it's a properly , runtime is the best bet , and giving the code may allow them to realize it, when someone see's code a lot of time they C&P and don't read the text prior. I din't even see it because I meticulously read over your code, so I didn't see it because I myself didn't read the preceding text
Prevents it from being copy & pasted. I want people 2 read my posts
Good point, so warning to all , read the posts, don't focus on the code
Posts 1–15 of 36 · Page 1 of 3
This thread is closed for replies.

Tags for this Thread

None

Talk with us