private void tvColumns_DragDrop(Object sender, DragEventArgs e) { string sourceTableName; TreeNode sourceNode = (TreeNode)e.Data.GetData(typeof(TreeNode)); sourceTableName = sourceNode.TreeView.Parent.Name; Table sourceTable = (Table)sourceNode.TreeView.Parent; Point start = sourceNode.TreeView.Parent.Location; //start position of a line Debug.WriteLine("source parent point: " + start.ToString()); Debug.WriteLine("source node location: " + sourceNode.TreeView.PointToClient(new Point(e.X, e.Y))); string destinationTableName; TreeNode destinationNode; Table targetTable; Point destinationPoint = tvColumns.PointToClient(new Point(e.X, e.Y)); //destination of the tree node where we do the drop destinationNode = tvColumns.GetNodeAt(destinationPoint); Point end = destinationNode.TreeView.Parent.Location; //end position of a line; Debug.WriteLine("dest parent point: " + end.ToString()); Debug.WriteLine("dest node location: " + destinationNode.TreeView.PointToClient(new Point(e.X, e.Y))); if (destinationNode != null) { destinationTableName = (sender as TreeView).Parent.Name; targetTable = (Table)destinationNode.TreeView.Parent; if (sourceTableName.Equals(destinationTableName)) { e.Effect = DragDropEffects.None; return; } //Debug.WriteLine("drag from : " + sourceNode.Text); //Debug.WriteLine("drag from table: " + sourceNode.TreeView.Parent.Name); Debug.WriteLine("Drop at: " + destinationNode.Text); Debug.WriteLine("Drop at table: " + (sender as TreeView).Parent.Name); ///drawing line FormJoin frm = (FormJoin)destinationNode.TreeView.Parent.Parent.Parent.Parent.Parent.Parent; Relationship rel = new Relationship(); rel.From = sourceTable; rel.SrcPoint = start; rel.SrcOffset = sourceNode.TreeView.PointToClient(new Point(e.X, e.Y)); rel.To = targetTable; rel.TargetPoint = end; rel.TargetOffset = destinationNode.TreeView.PointToClient(new Point(e.X, e.Y)); rel.FromColumn = sourceNode.Text; rel.ToColumn = destinationNode.Text; frm.onCallback(rel); } }
public void onCallback(Relationship rel) { this.relationship.Add(rel); this.panel1.Invalidate(); }