Search code examples
windowsvb.netformsdrag-and-dropmouseevent

Using a property of the Sender object for MouseMove Handler for Drag Drop


I'm sorry the question isn't clearer. I was setting up some drag drop based on code in this post. Get name of controls for MouseDown and DragDrop

The two controls I am using are different. The source is a list and the destination is text. To capture the row of text I want from the list I need to use the .selectedText property.

     '''
     C1List1.DoDragDrop(C1List1.SelectedText, DragDropEffects.Copy)
     '''

Is there a way to make it generic for any list control? '''sender.selectedText''' obviously doesn't work but something like this that will work is what I'm looking for.

    '''C1List1.DoDragDrop(Sender.SelectedText, DragDropEffects.Copy)'''

Solution

  • The sender parameter is type Object in a proper event handler, so if you want to use it as some other type then you need to cast as that type, e.g. DirectCast(sender, ListControl). You can then access members of that type on that reference.