Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 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