We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Drag and Drop into Grid

Hi everybody, I have the following scenario: one tree and one grid The Nodes of the tree must be dropped into the grid, but a drop is not allowed everywhere. Is there a possibility to validate during drag which coordinates (row, col) the cell under the cursor has? i tried it with Private Sub GridControl1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles GridControl1.DragOver e.Effect = Windows.Forms.DragDropEffects.All Dim lrange As GridRangeInfo lrange = GridControl1.PointToRangeInfo(New System.Drawing.Point(e.X, e.Y)) Me.GridControl1.Selections.SelectRange(lrange, True) End Sub But allways the last cell is selected. Thanks for your help. regards. kai

1 Reply

AD Administrator Syncfusion Team March 12, 2004 09:11 AM UTC

There is a problem in using Windows Forms Drag events with the grid. The problem is that the grid also has some objects that listen to these events, and there is no guarantee your listener will be hit before/after the grid''s listener. So, there is no way to ''know'' whose settings are going to take effect when several listeners subscribe to the same event. This is a generic Windows Forms events problem, and is one of the negatives (or positives depending on your point of view???) to the event architecture. One solution to this problem is to not use events, but to derive the control and override the accopanying OnEventXXXX method that, by convention, is provided by the Framework. This way, you can control what setting is returned. Below is code that does not let you drop on row 3. (The range indicator frame will not move into row 3). Protected Overrides Sub OnDragOver(drgevent As System.Windows.Forms.DragEventArgs) Dim pt As Point = Me.PointToClient(New Point(drgevent.X, drgevent.Y)) Dim row, col As Integer If Me.PointToRowCol(pt, row, col, 1) Then If row = 3 Then drgevent.Effect = DragDropEffects.None Return End If End If MyBase.OnDragOver(drgevent) End Sub ''OnDragOver

Live Chat Icon For mobile
Up arrow icon