Drag and drop problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Griff

    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.GetDataP resent(DataForm ats.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.Ge tData(DataForma ts.FileDrop),
    String())

    Neither event appears to fire though.

    Any suggestions would be most welcome

    Many thanks

    Griff


  • zacks@construction-imaging.com

    #2
    Re: Drag and drop problem

    On Feb 7, 9:10 am, "Griff" <GriffithsJ_... @htomail.comwro te:
    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.GetDataP resent(DataForm ats.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.Ge tData(DataForma ts.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?

    Comment

    • Griff

      #3
      Re: Drag and drop problem

      Did you set the AllowDrop property of the textbox and the form to True?

      Yup


      Comment

      • zacks@construction-imaging.com

        #4
        Re: Drag and drop problem

        On Feb 7, 11:27 am, "Griff" <GriffithsJ_... @htomail.comwro te:
        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?

        Comment

        • Griff

          #5
          Re: Drag and drop problem

          >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 HorizontalConte ntAlignment="Le ft" Margin="146,13, 12,0"
          Name="txtFile" AllowDrop="True " Height="25" VerticalAlignme nt="Top">

          <TextBox.Bitmap Effect>

          <OuterGlowBitma pEffect />

          </TextBox.BitmapE ffect>

          </TextBox>


          Comment

          • zacks@construction-imaging.com

            #6
            Re: Drag and drop problem

            On Feb 7, 12:05 pm, "Griff" <GriffithsJ_... @htomail.comwro te:
            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 HorizontalConte ntAlignment="Le ft" Margin="146,13, 12,0"
            Name="txtFile" AllowDrop="True " Height="25" VerticalAlignme nt="Top">
            >
            <TextBox.Bitmap Effect>
            >
            <OuterGlowBitma pEffect />
            >
            </TextBox.BitmapE ffect>
            >
            </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_DragEn ter(ByVal sender As Object, ByVal e As
            System.Windows. Forms.DragEvent Args) Handles txtQuery.DragEn ter

            Dim fi As FileInfo
            Dim sFiles As String()

            If e.Data.GetDataP resent(DataForm ats.FileDrop) Then
            sFiles = CType(e.Data.Ge tData(DataForma ts.FileDrop),
            String())
            fi = New FileInfo(sFiles (0))
            If fi.Extension.To Upper = ".SQL" Then
            If sFiles.GetUpper Bound(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_DragDr op(ByVal sender As Object, ByVal e As
            System.Windows. Forms.DragEvent Args) Handles txtQuery.DragDr op

            Dim myReader As StreamReader
            Dim sFiles As String()

            If e.Data.GetDataP resent(DataForm ats.FileDrop) Then
            sFiles = CType(e.Data.Ge tData(DataForma ts.FileDrop),
            String())
            myReader = New StreamReader(sF iles(0))
            txtQuery.Text = myReader.ReadTo End
            myReader.Close( )
            End If

            End Sub

            Comment

            Working...