473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Drag and drop problem

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
5 4663
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
Did you set the AllowDrop property of the textbox and the form to True?

Yup
Feb 7 '08 #3
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
>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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Wang, Jay | last post by:
Hello, all, I would like to enable some text between <SPAN url="http://www.testserver.com/">WORD TO BE DRAGGED </SPAN>. I put some javascript and it will extract http://www.testserver.com/ from...
2
by: matthewmacchia | last post by:
I believe this is a Firefox bug but I was hoping someone found a workaround. I have implemented drag and drop functionality, but if I try to drag an element from a div that happens to have a div...
6
by: hemant_mishal | last post by:
Hi All, I am writting a java script library which will provide inter frame drag and drop operation. The more precise will be OLE drag and drop, which means only data will be transfered from frame...
0
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
8
by: benkial | last post by:
I am writing a small GUI tool in C#, and I want to experiment some fancy trick as follows: when the user click on a "OK" button, the code will initiate a "Drag and Drop" operation in the GUI itself...
2
by: Robert Zahm | last post by:
I have created a C# user control which display certain filesystem information, and allows the user to drag an drop files into and out of the control. I then placed this user form in IE using an...
14
by: maya | last post by:
I need a drag-n-drop script.. I have found one here.. http://javascript.internet.com/page-details/drag-n-drop.html each div containing an image has an id, and each image has a name, as in ...
0
by: RHSFSS | last post by:
Hi, I have a Drag and Drop registration problem (See http://www.thescripts.com/forum/thread434707.html for similar problem post), can anyone out thereadvise on the best solution? I have a .NET 2.0 ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.