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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Drag n Drop tree node

Thread ID:





33906 Aug 29,2005 03:37 PM UTC Aug 30,2005 01:30 PM UTC Windows Forms 8
Tags: GridControl
Administrator [Syncfusion]
Asked On August 29, 2005 03:37 PM UTC

Hi, I''ve used the VirtTreeGrid code to create a tree in the row header of the grid. I want my user to be able to drag and drop row to modify the tree in real time. The problem is when a row is selected; the user can not expand or collapse the tree because the drag event is enabled when the mouse down event is called. Is there a solution to this?

Administrator [Syncfusion]
Replied On August 29, 2005 04:06 PM UTC

Check out this forum thread to see if the technique discussed there handles the problem you are seeing. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=4470

Administrator [Syncfusion]
Replied On August 29, 2005 06:00 PM UTC

I''ve overrides the OnHitTest in the GridStaticCellRenderer Protected Overloads Overrides Function OnHitTest(ByVal row_index As Integer, ByVal col_index As Integer, ByVal e As MouseEventArgs, ByVal controller As Syncfusion.Windows.Forms.IMouseController) As Integer If e.X < 100 Then Return 1 End If Return 0 End Function When I click on the left side of the cell, everything handles perfectly (no drag). When I click on the right side I can drag drop, but when I come back to the left side I''m able to drag and drop (it seem to ignore the code).

Administrator [Syncfusion]
Replied On August 29, 2005 06:31 PM UTC

>>because the drag event is enabled when the mouse down event is called. Are you calling DoDragDrop in OnMouseDown? Is this what you mean by the drag event is enabled when mouse down is called? If so, then you should move the call to DoDragDrop from OnMouseDown to OnMouseMove. Then in OnMouseDown, set a variable to be remember the mousedown point. Then in your OnMouseMove, if e.Button = Left and if the mouse point is further than SystemInformation.DragSize away from the MouseDown point (that you saved in OnMouseDown), then call DoDragDrop. Waiting until your user has moved the mouse outside of the DragSize will allow a click to happen normally.

Administrator [Syncfusion]
Replied On August 29, 2005 06:36 PM UTC

I set the: Me.AllowDragSelectedRows = True And I will handle the TreeGridControl_SelectionDragging to call my own DoDragDrop(info, DragDropEffects.Move) Should I do this differently?

Administrator [Syncfusion]
Replied On August 29, 2005 06:53 PM UTC

Yes. I would try turning off the grid''s row moving and initiating the DowDagDrop in MouseMove instead. Here is a KB link that shows how you can go about this. http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=236 Just look at how the move is triggerred in the code of the sample using OnMouseDown and OnMouseMove.

Administrator [Syncfusion]
Replied On August 29, 2005 07:10 PM UTC

Great, no need of the OnHitTest. Now I only need to find out how to enable the selection of 1 row only. I want to user to highlight 1 row on a single click. Right now rows are being selected as a row is being dragged. I tried: Me.AllowSelection = Me.AllowSelection And (Not GridSelectionFlags.Multiple) With no success.

Administrator [Syncfusion]
Replied On August 29, 2005 08:44 PM UTC

You can try setting grid.ListBosSelectionMode = One to see if that gives you waht you want. Another thing you can do if you want to seelct the row when your user clicks the first cell is to modify the OnCellClick in the renderer class. There you can explicitly sect the row if you do not click the +/- button. Protected Overloads Overrides Sub OnClick(ByVal rowIndex As Integer, ByVal colIndex As Integer, ByVal e As MouseEventArgs) Me.Grid.Selections.Clear(False) Dim rect As Rectangle rect = GetCellBoundsCore(rowIndex, colIndex) Dim X As Integer X = (rect.X _ + (IndentSize * CType(Me.Grid.Model(rowIndex, colIndex).Tag, Integer))) rect.X = X rect.Width = Me.bitmapWidth rect.Height = Me.bitmapHeight '' } If rect.Contains(New Point(e.X, e.Y)) Then If (Me.Grid.Model(rowIndex, colIndex).ImageIndex = CType(TreeNodeState.Opened, Integer)) Then Me.Grid.Model(rowIndex, colIndex).ImageIndex = CType(TreeNodeState.Closed, Integer) OnCollapseRow(rowIndex) Else If (Me.Grid.Model(rowIndex, colIndex).ImageIndex = CType(TreeNodeState.Closed, Integer)) Then Me.Grid.Model(rowIndex, colIndex).ImageIndex = CType(TreeNodeState.Opened, Integer) OnExpandRow(rowIndex) End If End If Else Me.Grid.Selections.SelectRange(GridRangeInfo.Row(rowIndex), True) MyBase.OnClick(rowIndex, 0, e) ''set it to col 0 so you do not see a white cell End If End Sub

Administrator [Syncfusion]
Replied On August 30, 2005 01:30 PM UTC

Thanks, its working. I modified the OnClick, the other option did not do what I wanted.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon