Solved

How to loop DragAndDrop method for all Form's or TabControl's TextBoxes.

Posted on 2013-12-31
3
252 Views
Last Modified: 2014-01-11
Hi,
I'm trying to avoid writing same DragAndDrope code for all textboxes inside of tabcontrol. And, I would be pleased if someone could show me. I was googling, but did not found anything proper. Also trying to write similar code for Form DragDrop events, but not successfull.

    Private Sub TextBoxMapUniqueID_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBoxMapUniqueID.DragEnter
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub TextBoxMapUniqueID_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBoxMapUniqueID.DragDrop
        TextBoxMapUniqueID.Text = e.Data.GetData(DataFormats.Text)
    End Sub

Open in new window


Thanks in advance for help.
0
Comment
Question by:dejandejanovic
3 Comments
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 100 total points
ID: 39748841
Sorry, I do not have time to show you code.

I you know about inheritance, create your own TextBox by inheriting from TextBox, and override the OnDragEnter and OnDragDrop in your class. The use your own instead of the standard TextBox.

If you are not familiar with inheritance, a simpler way would be to add a UserControl to your project (from the Project menu). Put a TextBox on the UserControl. Program it as you would do in your form and compile. The UserControl should show in the Toolbox, and you can use it instead of the regular TextBox.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 400 total points
ID: 39754915
What you can do is to add the  comma separated names of all textboxes at the end of event handlers like below

Private Sub TextBoxMapUniqueID_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBoxMapUniqueID.DragDrop, Textbox2.DragDrop, Textbox3.DragDrop

and then change the dragdrop code from

TextBoxMapUniqueID.Text = e.Data.GetData(DataFormats.Text)

to

CType(sender, TextBox).Text = e.Data.GetData(DataFormats.Text)
0
 

Author Closing Comment

by:dejandejanovic
ID: 39773879
Nice code CodeCruiser, it really works. Intereseting that control can invite also another controls to handle Sub line.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now