Solved

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

Posted on 2013-12-31
3
253 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

25 Experts available now in Live!

Get 1:1 Help Now