View previous topic :: View next topic |
Author |
Message |
paymark
Joined: 26 Jan 2006 Posts: 3
|
Posted: Thu Feb 16, 2006 7:00 pm Post subject: Treeview Drag & Drop Support |
|
|
any one please help . CURRENTLY I am evaluating the demo version of Virtual Tree and i am able to the drag & drop. But the problem occurs when i am using 2 virtual tree and from one Tree to another TRee I am dragging , Then the Node automatically removed from the source Tree . If I don't want happen this , What settings I have to do .
Also How can i Do drag & Drop between TRee View ( .NET component ) and Virtual TRee View.
IF U REQUIRE THE CODE FOR THE ABOVE PROGRAM PLEASE LET ME KNOW ,
LOOKING FOR ASAP support.
|
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Feb 16, 2006 9:25 pm Post subject: |
|
|
What type of binding are you using (programmatic, object binding or dataset binding)?
In general Virtual Tree will support drag and drop of rows within the same tree without any programming for object binding and dataset binding.
For dropping between Virtual Trees or from .NET TreeView then you typically need to handle the row level drag/drop events yourself ie you need to handle the following events (or override their corresponding methods)
* AllowedRowDropLocations
* RowDropEffect
* OnRowDrop
The data dropped when dragging from a Virtual Tree is an array of the Rows so you typically need to check for this and convert eg
Code: | Row[] dropRows = e.Data.GetData(typeof(Row[])) as Row[];
if (dropRows != null)
{
// perform your drop operation
} |
If you email your sample programs to support@infralution.com then we will take a look at them for you. _________________ Infralution Support |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Feb 19, 2006 11:27 pm Post subject: |
|
|
Thanks for the sample project. The main issue was that you had created two separate virtual tree controls but had only attached your event handlers to the first. This means that your event handlers were only getting called for the first control. The second issue is that if you want to implement copy semantics then you need to handle this yourself by handling the OnRowDrop event and copying the data yourself. The object bindings by default handle only moving rows. To do this you need to add a method in the Part class as follows:
Code: |
' Create a copy of this part and all its children recursively
'
Public Function Copy(ByVal newParent As Part) As Part
Dim sPart As New Part(newParent, _name, _stockLevel)
For Each sChildPart As Part In ChildParts
sChildPart.Copy(sPart)
Next
Return sPart
End Function
|
The event handlers then to allow drag and drop copying between trees are then as follows
Code: | Private Sub VirtualTree_GetAllowedRowDropLocations(ByVal sender As Object, ByVal e As GetAllowedRowDropLocationsEventArgs) Handles VirtualTree.GetAllowedRowDropLocations, VirtualTree1.GetAllowedRowDropLocations
Dim dropRows As Row() = e.Data.GetData(GetType(Row()))
If Not dropRows Is Nothing Then
' only allow rows to be dropped from one tree to the other '
If Not dropRows(0).Tree Is sender Then
e.AllowedDropLocations = RowDropLocation.OnRow
End If
End If
End Sub
Private Sub VirtualTree_GetRowDropEffect(ByVal sender As Object, ByVal e As GetRowDropEffectEventArgs) Handles VirtualTree.GetRowDropEffect, VirtualTree1.GetRowDropEffect
e.DropEffect = DragDropEffects.Copy
End Sub
Private Sub VirtualTree_RowDrop(ByVal sender As Object, ByVal e As RowDropEventArgs) Handles VirtualTree.RowDrop, VirtualTree1.RowDrop
Dim dropRows As Row() = e.Data.GetData(GetType(Row()))
If Not dropRows Is Nothing Then
Dim sParentPart As Part = e.Row.Item
For Each dropRow As Row In dropRows
Dim sDropPart As Part = dropRow.Item
sDropPart.Copy(sParentPart)
Next
' force the tree to update the display
'
CType(sender, VirtualTree).UpdateRows()
End If
End Sub |
We will email you back the modified project. If you are using multiple controls you would probably be better off creating another control that contains virtual tree that implements this or deriving a control from virtual tree and overriding the corresponding event methods. That way you don't have to maintain multiple sets of columns and row bindings. _________________ Infralution Support |
|
Back to top |
|
|
|