Drag and drop problem

G

Griff

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
 
Z

zacks

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?
 
G

Griff

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>
 
Z

zacks

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
 
G

Griff

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?

Well, there's no real concept of the form in WPF (from looking at the XAML),
but I've got the AllowDrop set on the Window:
<Window x:Class="winStartUp"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Interface Files" Height="547" Width="772" AllowDrop="True">

In the New() event of the window, the following returns "True":
MessageBox.Show(Me.AllowDrop.ToString)

The text box also has this property
<TextBox HorizontalContentAlignment="Left" Margin="146,13,12,0"
Name="txtFolder" AllowDrop="True" Height="25" VerticalAlignment="Top">



</TextBox>

Because it's WPF, the event signature is slighty different too. Yours is:

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

Whilst mine is:
Private Sub txtFolder_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.DragEventArgs) Handles txtFolder.DragEnter

System.Windows.Forms.DragEventArgs vs System.Windows.DragEventArgs

Other than that, pretty similar.

Thanks

Griff
 

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