Results 1 to 3 of 3

Thread: Determining the source object in a drag and drop

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153

    Determining the source object in a drag and drop

    Hi guys,

    I've been playing around with drag and drop for the first time and got it working all correctly. Except, I need a way to determine the source object that the payload came from.

    Since at the moment I'm moving between listboxes and treeviews I could just include the sender in the payload (as it's text), however, if I decide later on I want to move other data as well, is there a more elegant way of finding the source object? (I guess another way would be too have a private variable that keeps track of the drag and drop operations and stores the sender)

    The sender parameter obviously returns the destination object as it is the one calling the DragDrop event handler.

    If anyone knows of an elegant way to determine the sender object then this would be appreciated.

    Thanks.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can use TypeOf in an expression if you think you know what it is:
    If TypeOf Sender Is Gettype(Textbox) Then

    Or you can get the name using either:

    Sender.Gettype.Name
    or
    TypeName(sender)

  3. #3
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307
    I also have this problem!

    I have solved it by using a global variable, not very elegant, but it works.

    I have this at the top of my class, in the declarations section:-
    Code:
    public dragSource as object
    Then in the DragEnter event of my destination control I have:-
    Code:
    If DragSource.name <> "tree_Shortcuts_Available" Then
                e.Effect = DragDropEffects.None
            Else
                e.Effect = DragDropEffects.Copy
            End If
    tree_Shortcuts_Available is the name of the only control that is allowed to drop onto this destination control.

    Then in the DragDrop event I have:-
    Code:
    'We can only accept items from the shortcuts available
            'tree view control.
            If DragSource.name <> "tree_Shortcuts_Available" Then
                DragSource = Nothing
                Exit Sub
            End If
    As I say, it's probably untidy and certainly not elegant, but it works for me.
    "I'm Brian and so is my Wife"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width