Solved

VB.net get cell row and column number in TableLayoutPanel after drag and drop

Posted on 2014-02-02
2
1,220 Views
Last Modified: 2014-02-03
How do I get cell row and column number in TableLayoutPanel after drag and drop
done using the following code:

   Dim ptOriginal As Point = Point.Empty


    Private Sub BarChart_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles BarChart.MouseDown
        Try
            ptOriginal = New Point(e.X, e.Y)
            Me.TableLayoutPanel1.AllowDrop = True
            DirectCast(sender, Control).DoDragDrop(sender, DragDropEffects.All)
        Catch ex As Exception
            MsgBox("There was an error dragging " & ex.Message)
        End Try
    End Sub

   

    Private Sub TableLayoutPanel1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles TableLayoutPanel1.DragEnter
        If e.Data.GetDataPresent(GetType(System.Windows.Forms.Panel)) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub

    Private Sub TableLayoutPanel1_DragOver(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles TableLayoutPanel1.DragOver
        DirectCast(e.Data.GetData(GetType(System.Windows.Forms.Panel)), Control).Location = Me.PointToClient(New Point(e.X - ptOriginal.X, e.Y - ptOriginal.Y))
        DirectCast(e.Data.GetData(GetType(System.Windows.Forms.Panel)), Control).BringToFront()
    End Sub

    Private Sub TableLayoutPanel1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles TableLayoutPanel1.DragDrop
        DirectCast(e.Data.GetData(GetType(System.Windows.Forms.Panel)), Panel).BringToFront()
    End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 16

Accepted Solution

by:
SriVaddadi earned 500 total points
ID: 39829553
Use GetChildAtPoint(Point) and GetPositionFromControl methods to get the TableLayoutPanelCellPosition for the point (cursor position from DragEventArgs X and Y)
0
 

Author Closing Comment

by:murbro
ID: 39829561
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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