Connecting Tech Pros Worldwide Help | Site Map

[C# Windows Forms] Drag Drop behaviour

Shashi Sadasivan's Avatar
Moderator
 
Join Date: Aug 2007
Location: Brisbane, Australia
Posts: 1,414
#1: Nov 16 '07
Hi all,
I have a scenario where i have to drag data from one form to another.
both contain 3rd party gridviews
and the user can select multiple rows.
Data can be dragged and dropped from any grid from either form to another one (infact there are about 6 forms, each with a grid, displaying the same data schema)

I use the mouse down event to capture all the rows selected and start the doDragDrop event for that grid
and have handled the dragDrop event too
for each of the grids.

The issue is that if i click on a grid (click and release) and then go across to the other form and click on it , the data is transferred to that grid (as if it was a drag and drop event)

I did have the queryContinueDrag event where i captured if the left mouse button was clicked, but this obviously cancelled the evenet the moment i released the mouse.

any possible fixes to this issue?

- the other thing is that once i click once (and release) on a grid, i have to click twice to select something elese in the MDI parent! (the MDI parent is a Ribbon style form)
CyberSoftHari's Avatar
Expert
 
Join Date: Sep 2007
Location: Banglore, India.
Posts: 450
#2: Nov 16 '07

re: [C# Windows Forms] Drag Drop behaviour


You can use
Expand|Select|Wrap|Line Numbers
  1. IResourceWriter
To save data as file to specific path on mouse click (If there is a file already then read it from there and drop it in another form control on click).

Expand|Select|Wrap|Line Numbers
  1. ResourceSet
will read the file content.
Shashi Sadasivan's Avatar
Moderator
 
Join Date: Aug 2007
Location: Brisbane, Australia
Posts: 1,414
#3: Nov 16 '07

re: [C# Windows Forms] Drag Drop behaviour


Quote:

Originally Posted by CyberSoftHari

You can use

Expand|Select|Wrap|Line Numbers
  1. IResourceWriter
To save data as file to specific path on mouse click (If there is a file already then read it from there and drop it in another form control on click).

Expand|Select|Wrap|Line Numbers
  1. ResourceSet
will read the file content.

never wanted to save it to a file!
I dont think that would be required, as the data being dragged isint immensly huge.
CyberSoftHari's Avatar
Expert
 
Join Date: Sep 2007
Location: Banglore, India.
Posts: 450
#4: Nov 16 '07

re: [C# Windows Forms] Drag Drop behaviour


The only way to drag and drop is to hold the mouse click and release it in another form.

But you want it in mouse down then you have to store data somewhere, if data isn’t huge then store it in database or use a temporary public variable.
Shashi Sadasivan's Avatar
Moderator
 
Join Date: Aug 2007
Location: Brisbane, Australia
Posts: 1,414
#5: Nov 16 '07

re: [C# Windows Forms] Drag Drop behaviour


Quote:

Originally Posted by CyberSoftHari

The only way to drag and drop is to hold the mouse click and release it in another form.

But you want it in mouse down then you have to store data somewhere, if data isn’t huge then store it in database or use a temporary public variable.

Ok, I think I did not make it entirely clear.
The whole drag and drop thing works fine.
The BUG: I click on the grid (and release it) then i go to the other forms grid and click there. The drag event apparantly happens. I dont want this to happen.

I know that my mouse-down event fires the drag event, and the dragDrop event is fired the moment i click on the other grid (when the mouse is clicked and released)

My question here is on how to I go about avoiding this scenario
CyberSoftHari's Avatar
Expert
 
Join Date: Sep 2007
Location: Banglore, India.
Posts: 450
#6: Nov 16 '07

re: [C# Windows Forms] Drag Drop behaviour


LET ME CLEAR.....!

Did you mean...

Expand|Select|Wrap|Line Numbers
  1. private void ControlName_DragDrop(object sender, DragEventArgs e)
  2.         {
  3.                      e.Data // this wll be your Data which is draged.
  4.  
  5.         }
Is it correct?
Shashi Sadasivan's Avatar
Moderator
 
Join Date: Aug 2007
Location: Brisbane, Australia
Posts: 1,414
#7: Nov 16 '07

re: [C# Windows Forms] Drag Drop behaviour


Quote:

Originally Posted by CyberSoftHari

LET ME CLEAR.....!

Did you mean...

Expand|Select|Wrap|Line Numbers
  1. private void ControlName_DragDrop(object sender, DragEventArgs e)
  2.         {
  3.                      e.Data // this wll be your Data which is draged.
  4.  
  5.         }
Is it correct?

yes, on that event i am checking if the data being dragged is of my object ttype, and then do the drop action.

and thats how I start my drag event
these 2 event handlers are the same code pasted in them
Expand|Select|Wrap|Line Numbers
  1. private void ControlName_MouseDown(object sender, MouseEventArgs e)
  2.         {
  3.             if (e.Button == MouseButtons.Left)
  4.             {
  5.                 //creating object obj
  6.                  ControlName.DodragDrop(obj, DragDropEffects.Move);
  7.             }
  8.         }
cheers
CyberSoftHari's Avatar
Expert
 
Join Date: Sep 2007
Location: Banglore, India.
Posts: 450
#8: Nov 16 '07

re: [C# Windows Forms] Drag Drop behaviour


Did your problem solved?
Shashi Sadasivan's Avatar
Moderator
 
Join Date: Aug 2007
Location: Brisbane, Australia
Posts: 1,414
#9: Nov 16 '07

re: [C# Windows Forms] Drag Drop behaviour


No,
i posted what i had already.
I thought you were not clear when i posted my query in a pseudo code manner
Newbie
 
Join Date: Mar 2009
Location: Czech Republic
Posts: 1
#10: May 20 '09

re: [C# Windows Forms] Drag Drop behaviour


Solution to your problem is: use ItemDrag event instead of MouseDown
Reply