Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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