Click to See Complete Forum and Search --> : drag drop doesn't work...please help
Mansi
March 13th, 2003, 01:48 PM
Hi,
I think there is some silly mistake that I'm making...can anyone get this program to work??
My form has 2 panels. One has a TreeView and the other panel has a TabControl with one TabPage. This I call as OuterTabControl and OuterTabPage. The OuterTabPage has another TabControl with one TabPage with I call as InnerTabControl and InnerTabPage.
Now I want to drag and drop the node data of treeview onto the InnerTabPage.
The data is just String and I want it to get displaying on the TabPage at the point where I drop.
I have attached the code.
Some C# GUI guru please help.
thanks
-Mansi.
Mansi
March 13th, 2003, 01:49 PM
Oops ! I forgot to attach
pareshgh
March 13th, 2003, 02:09 PM
i think u will need following things to be changed herez the code,
-------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DragDropTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabControl tabControl2;
private System.Windows.Forms.TreeView treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private String m_strData;
private System.Windows.Forms.TabPage OuterTabPage;
private System.Windows.Forms.TabPage InnerTabPage;
private PointF m_Pos;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
String str1 = "Child 1 data I want to drag and drop";
String str2 = "Child 2 data I want to drag and drop";
this.treeView1.Nodes[0].Nodes[0].Tag = str1;
this.treeView1.Nodes[0].Nodes[1].Tag = str2;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.treeView1 = new System.Windows.Forms.TreeView();
this.panel2 = new System.Windows.Forms.Panel();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.OuterTabPage = new System.Windows.Forms.TabPage();
this.tabControl2 = new System.Windows.Forms.TabControl();
this.InnerTabPage = new System.Windows.Forms.TabPage();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.tabControl1.SuspendLayout();
this.OuterTabPage.SuspendLayout();
this.tabControl2.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.treeView1});
this.panel1.Location = new System.Drawing.Point(8, 8);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 296);
this.panel1.TabIndex = 0;
//
// treeView1
//
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(16, 32);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Parent", new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Child 1"),
new System.Windows.Forms.TreeNode("Child 2")})});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(152, 200);
this.treeView1.TabIndex = 1;
this.treeView1.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeView1_ItemDrag);
//
// panel2
//
this.panel2.AllowDrop = true;
this.panel2.BackColor = System.Drawing.Color.White;
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl1});
this.panel2.Location = new System.Drawing.Point(216, 8);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(248, 296);
this.panel2.TabIndex = 1;
//
// tabControl1
//
this.tabControl1.AllowDrop = true;
this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.OuterTabPage});
this.tabControl1.Location = new System.Drawing.Point(8, 8);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(232, 280);
this.tabControl1.TabIndex = 0;
//
// OuterTabPage
//
this.OuterTabPage.AllowDrop = true;
this.OuterTabPage.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl2});
this.OuterTabPage.Location = new System.Drawing.Point(4, 22);
this.OuterTabPage.Name = "OuterTabPage";
this.OuterTabPage.Size = new System.Drawing.Size(224, 254);
this.OuterTabPage.TabIndex = 0;
this.OuterTabPage.Text = "TabPage of Outer TabControl";
//
// tabControl2
//
this.tabControl2.Alignment = System.Windows.Forms.TabAlignment.Bottom;
this.tabControl2.AllowDrop = true;
this.tabControl2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.InnerTabPage});
this.tabControl2.Location = new System.Drawing.Point(8, 8);
this.tabControl2.Name = "tabControl2";
this.tabControl2.SelectedIndex = 0;
this.tabControl2.Size = new System.Drawing.Size(200, 240);
this.tabControl2.TabIndex = 0;
//
// InnerTabPage
//
this.InnerTabPage.AllowDrop = true;
this.InnerTabPage.Location = new System.Drawing.Point(4, 4);
this.InnerTabPage.Name = "InnerTabPage";
this.InnerTabPage.Size = new System.Drawing.Size(192, 214);
this.InnerTabPage.TabIndex = 0;
this.InnerTabPage.Text = "TabPage of Inner TabControl";
this.InnerTabPage.DragEnter += new System.Windows.Forms.DragEventHandler(this.InnerTabPage_DragEnter);
this.InnerTabPage.Paint += new System.Windows.Forms.PaintEventHandler(this.tabPageFlowView_Paint);
this.InnerTabPage.DragDrop += new System.Windows.Forms.DragEventHandler(this.tabPageFlowView_DragDrop);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(472, 310);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel2,
this.panel1});
this.Name = "Form1";
this.Text = "Drag Drop testing";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.OuterTabPage.ResumeLayout(false);
this.tabControl2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void treeView1_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
DoDragDrop((String)(((TreeNode)e.Item).Tag),DragDropEffects.Copy);
}
private void tabPageFlowView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
m_strData = (String)e.Data.GetData("System.String");
m_Pos = new PointF(e.X,e.Y);
this.InnerTabPage.Invalidate();
}
private void tabPageFlowView_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawString(m_strData,new Font("Arial",9),new SolidBrush(Color.Black),
m_Pos);
}
private void InnerTabPage_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
}
}
--------
hope this helps,
Paresh
Mansi
March 13th, 2003, 03:57 PM
Hey Paresh,
Thanks a lot for the quick reply....well u got it right...wasn't it so silly of me not to handle the DragEnter event as well?
Any idea how to associate a drag icon with the mouse movement??
-Mansi
pareshgh
March 13th, 2003, 04:03 PM
hi,
well it was not a mistake, normally we are habbited to convert the object using direct class and this one needs the specified class casting. :D ;)
Any idea how to associate a drag icon with the mouse movement??
Do you mean that When you move the mouse without even clicking the drag on tree and just by moving the mouse the drag icon is associated ?
if so then you can implement the mousemove event of tree and tab,
and do accordingly, I don't think that's a good idea.
usually drag-N-drop works on left click.
Paresh
Mansi
March 13th, 2003, 05:32 PM
no, I mean associate my own custom icon with the dragging. So when I start dragging from the TreeView my own icon should be associated with the mouse cursor and not the slashed circle.
any idea??
thanks
pareshgh
March 13th, 2003, 05:36 PM
yes that is possible. :D
you can assign /change mouse style etc in draging. plz reffer to MSDN for more details.
Paresh
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.