none
Can't drag and drop right RRS feed

  • Question

  • I want to be able to hold CTRL down to select multiple text entries and drag them all to certain text boxes.  Or even one at a time, but once I try dragging another word into the box it replace the first one.  Is there any way to just have it add to the text box rather than replace it?

    And if possible, place a "-" between each entry?


    EDIT:  Whoops, forgot to post the code I'm using.

    This is the pop-up form with the listbox that contains the words to drag:


     Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
            ListBox1.DoDragDrop(ListBox1.SelectedItem, DragDropEffects.Copy)
        End Sub




    And this is the main form which contains the textboxes I want to populate:




    Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles LocationTextBox.DragDrop
            LocationTextBox.Text = e.Data.GetData("System.String").ToString
    
        End Sub
        Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles LocationTextBox.DragEnter
            e.Effect = DragDropEffects.Copy
    
        End Sub

    • Edited by meef Tuesday, June 23, 2009 4:44 PM
    Tuesday, June 23, 2009 4:37 PM

All replies

  • If you use the </> button on the toolbar for this forum post editor, it will format your code much better.

    To answer your question, if you want to append to the TextBox, use this:

    LocationTextBox.Text &= e.Data.GetData("System.String"
    ).ToString

    Notice the &=

    Hope this helps.


    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    • Proposed as answer by --Steve-- Thursday, June 25, 2009 12:09 AM
    Tuesday, June 23, 2009 4:44 PM
  • That's how I always post the code, but then I edited it and spaced it out more and the format get ruined every time, making me re-do the whole thing.  Rather annoying actually.

    Thanks, I'll give that a try and report back.
    Tuesday, June 23, 2009 4:48 PM
  • try changing in the drag drop event where you assign to text box using += instead of =
    that will add the text to the end of whatever is in the textbox

        Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) _
            Handles LocationTextBox.DragDrop
            'LocationTextBox.Text = e.Data.GetData("System.String").ToString
            LocationTextBox.Text += e.Data.GetData("System.String").ToString
        End Sub
    
    

    P.S now when I edit post I delete code block and redo it from scratch so format isn't jacked
    • Edited by TechNoHick Tuesday, June 23, 2009 5:04 PM kuz
    Tuesday, June 23, 2009 4:59 PM
  • When you edit it, edit it in the designer that comes up from the </> instead of after it has been pasted into your message. That should hopefully give you better results.


    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Tuesday, June 23, 2009 5:04 PM
  • += is C#

    &= is the VB string append operator
    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Tuesday, June 23, 2009 5:05 PM
  • When you edit it, edit it in the designer that comes up from the </> instead of after it has been pasted into your message. That should hopefully give you better results.


    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!



    Yeah, but all I was trying to do was put more space between what I typed and the code after it was inserted, I wasn't spacing the code out itself :)  Seems like any time I edit and even add more text it ruins the formatting of the code...


    Anyway, your suggestion works and I got it to place the "-" between each, now I just need help with the issue below.


      For some reason when I try binding the listbox to a datasource I put in (it contains a table of words to be used in the listbox), it shows me a + sign like it will allow my to drop text in but then it doesn't insert anything.  Does this code not work for databound related things?

    I found out how to do the CTRL click to select multiple lines but as soon as I try to click and drag it only selects one.  Is there more code required or can't I do that?

    • Edited by meef Tuesday, June 23, 2009 6:09 PM
    Tuesday, June 23, 2009 5:09 PM
  • Ok, still not getting anywhere with it.  I don't understand why it won't add it if I use a data set to populate the listbox, but works fine if I manually add things to the listbox.
    Tuesday, June 23, 2009 6:51 PM
  • LISTBOX ?????   Your original question was how to add dropped text to a TextBox!   What is it that you are actually wanting some help with?

    To finish answering your original question , copy and paste this into your project.  You should REPLACE the code you have now with this code:

        Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles LocationTextBox.DragDrop
            LocationTextBox.Text &= "-" & e.Data.GetData("System.String").ToString
        End Sub
    

    This new subroutine will APPEND the dropped text to whatever is already in your TextBox.  The newly appended text will be separated by a "-" .



    Doug

    SEARCH ... then ask
    • Proposed as answer by --Steve-- Thursday, June 25, 2009 12:09 AM
    Tuesday, June 23, 2009 11:40 PM
  • Yes, I got that working as per my previous postings.  I obviously mixed up listbox and textbox in my last post, there are too many terms flying around and I'm rushing around trying to get it done and got them confused.

    This is my newest question from above: 


    "For some reason when I try binding the listbox to a datasource I put in (it contains a table of words to be used in the listbox), it shows me a + sign like it will allow my to drop text in but then it doesn't insert anything.  Does this code not work for databound related things?

    I found out how to do the CTRL click to select multiple lines but as soon as I try to click and drag it only selects one.  Is there more code required or can't I do that
    ?"

    I don't know if I should be making new topics when I have different questions pertaining to the same thing, that would be opposite of what most forums want but should I start a new thread for the above?
    Thursday, June 25, 2009 3:54 PM
  • Because you are dragging in the mouse down event what may be happening is after you select with Shift/Ctrl key to get multi selection
    when you drag you click again without Shift/Ctrl and as it is dragging it also selects just the item that is under mouse on the drag.

    try on your last selection dragging before letting the mouse button up

    Thursday, June 25, 2009 4:39 PM
  • Because you are dragging in the mouse down event what may be happening is after you select with Shift/Ctrl key to get multi selection
    when you drag you click again without Shift/Ctrl and as it is dragging it also selects just the item that is under mouse on the drag.

    try on your last selection dragging before letting the mouse button up

    When I try that they stay highlighted, but only the first item I selected is dropped into the box.  Would a different mouse event allow me to do this?

    My main problem is the fact that I can't get it to work when I populate the listbox with a table from a database.  Nothing gets dropped into the textboxes.
    Thursday, June 25, 2009 4:51 PM
  • Off first page.
    Thursday, June 25, 2009 6:35 PM