Solved

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

Posted on 2013-12-31
3
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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