By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

Drag and drop problem

P: n/a
Using VS2008/VBasic/WPF Application

I have a text box and wish to drap a file onto it from the file system
(explorer). I've tried to mimic what worked in VS2005 (Windows forms) and I
can't get it to work....when I drag the file onto the TextBox I get the "not
allowed" mouse symbol (a circle with a line through it).

The textbox has the AllowDrop property set to TRUE

The textbox's DragEnter() event has the following code:
If e.Data.GetDataPresent(DataFormats.FileDrop, False) Then

e.Effects = DragDropEffects.All

End If
And the textbox's Drop() event [VS2005 I used the DragDrop() event] has this
code (snippet):
Dim sData() As String = CType(e.Data.GetData(DataFormats.FileDrop),
String())

Neither event appears to fire though.

Any suggestions would be most welcome

Many thanks

Griff
Feb 7 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Feb 7, 9:10*am, "Griff" <GriffithsJ_...@htomail.comwrote:
Using VS2008/VBasic/WPF Application

I have a text box and wish to drap a file onto it from the file system
(explorer). *I've tried to mimic what worked in VS2005 (Windows forms) and I
can't get it to work....when I drag the file onto the TextBox I get the "not
allowed" mouse symbol (a circle with a line through it).

The textbox has the AllowDrop property set to TRUE

The textbox's DragEnter() event has the following code:
If e.Data.GetDataPresent(DataFormats.FileDrop, False) Then

* * e.Effects = DragDropEffects.All

End If

And the textbox's Drop() event [VS2005 I used the DragDrop() event] has this
code (snippet):
Dim sData() As String = CType(e.Data.GetData(DataFormats.FileDrop),
String())

Neither event appears to fire though.

Any suggestions would be most welcome

Many thanks

Griff
Did you set the AllowDrop property of the textbox and the form to
True?
Feb 7 '08 #2

P: n/a
Did you set the AllowDrop property of the textbox and the form to True?

Yup
Feb 7 '08 #3

P: n/a
On Feb 7, 11:27*am, "Griff" <GriffithsJ_...@htomail.comwrote:
Did you set the AllowDrop property of the textbox and the form to True?

Yup
What makes you think that the events do not appear to fire? Do you
have a debug.writeline in them?
Feb 7 '08 #4

P: n/a
>What makes you think that the events do not appear to fire? Do you
>have a debug.writeline in them?
Yes. I have break-points (also tried message boxes etc). I'm certain the
events don't fire.

XAML for the text box is as follows:
<TextBox HorizontalContentAlignment="Left" Margin="146,13,12,0"
Name="txtFile" AllowDrop="True" Height="25" VerticalAlignment="Top">

<TextBox.BitmapEffect>

<OuterGlowBitmapEffect />

</TextBox.BitmapEffect>

</TextBox>
Feb 7 '08 #5

P: n/a
On Feb 7, 12:05*pm, "Griff" <GriffithsJ_...@htomail.comwrote:
What makes you think that the events do not appear to fire? Do you
have a debug.writeline in them?

Yes. *I have break-points (also tried message boxes etc). *I'm certainthe
events don't fire.

XAML for the text box is as follows:
<TextBox HorizontalContentAlignment="Left" Margin="146,13,12,0"
Name="txtFile" AllowDrop="True" Height="25" VerticalAlignment="Top">

<TextBox.BitmapEffect>

<OuterGlowBitmapEffect />

</TextBox.BitmapEffect>

</TextBox>
I only replied because I just recently figured out for the first time
how Drag and Drop works in .NET. I really can'y say why the event's
don't seem to be firing. You mention that you set the AllowDrop for
the TextBox, but are you sure you enabled it for the form as well?

Here is the working code from my application's form that makies use of
DragDrop when editing a SQL Query:

Private Sub txtQuery_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles txtQuery.DragEnter

Dim fi As FileInfo
Dim sFiles As String()

If e.Data.GetDataPresent(DataFormats.FileDrop) Then
sFiles = CType(e.Data.GetData(DataFormats.FileDrop),
String())
fi = New FileInfo(sFiles(0))
If fi.Extension.ToUpper = ".SQL" Then
If sFiles.GetUpperBound(0) = 0 Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
Else
e.Effect = DragDropEffects.None
End If
Else
e.Effect = DragDropEffects.None
End If

End Sub

Private Sub txtQuery_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles txtQuery.DragDrop

Dim myReader As StreamReader
Dim sFiles As String()

If e.Data.GetDataPresent(DataFormats.FileDrop) Then
sFiles = CType(e.Data.GetData(DataFormats.FileDrop),
String())
myReader = New StreamReader(sFiles(0))
txtQuery.Text = myReader.ReadToEnd
myReader.Close()
End If

End Sub

Feb 7 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.