Using drag and drop in c#
-
Hi, I am trying to drag files from windows explorer and openFileDialog box to the datagridview in c# 2005. I am able to drag files from windows explorer but i am not able to drag files from the openFileDialog box which invoked by my application through a button.Why it is happening like this and how can i fix this ? Thanks in Advance Phanindra...
-
Hi, I am trying to drag files from windows explorer and openFileDialog box to the datagridview in c# 2005. I am able to drag files from windows explorer but i am not able to drag files from the openFileDialog box which invoked by my application through a button.Why it is happening like this and how can i fix this ? Thanks in Advance Phanindra...
The OpenFileDialog is most probably a modal dialog. Your application will not react to mouse or keyboard input or, in this case, to darg-and-drop events. Is there a reason why you won't let the user select files in the OpenFileDialog and wait till he/she presses OK? -- modified at 8:26 Monday 3rd July, 2006 On second thought, what I wrote above is complete nonsense :rolleyes:. I just remembered I did something similar in one of my applications. You can drag files out of your OpenFileDialog just the same as out of, say, Explorer. You can use one and the same DragDrop event handler. Maybe you should post the code of your DragDrop event handler so we can take a look.
-
The OpenFileDialog is most probably a modal dialog. Your application will not react to mouse or keyboard input or, in this case, to darg-and-drop events. Is there a reason why you won't let the user select files in the OpenFileDialog and wait till he/she presses OK? -- modified at 8:26 Monday 3rd July, 2006 On second thought, what I wrote above is complete nonsense :rolleyes:. I just remembered I did something similar in one of my applications. You can drag files out of your OpenFileDialog just the same as out of, say, Explorer. You can use one and the same DragDrop event handler. Maybe you should post the code of your DragDrop event handler so we can take a look.
Hai, Thanks for ur reply. Here is the code for the drag drop event handler for the datagridview. private void dataGridView1_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Move; } private void dataGridView1_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); addFiles(files);//this method adds files to the datagridview } and i set datagridview property AllowDrop to true what else i should do. Phanindra...
-
Hai, Thanks for ur reply. Here is the code for the drag drop event handler for the datagridview. private void dataGridView1_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Move; } private void dataGridView1_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); addFiles(files);//this method adds files to the datagridview } and i set datagridview property AllowDrop to true what else i should do. Phanindra...
I can see nothing wrong with this code. And you say that this code DOES work when you drag from Windows Explorer and NOT from the OpenFileDialog? Have you placed a breakpoint in the method dataGridView1_DragDrop to see whether this method gets called at all. I just want to be certain the problem does not occur further on, for instance in "addFiles".
-
I can see nothing wrong with this code. And you say that this code DOES work when you drag from Windows Explorer and NOT from the OpenFileDialog? Have you placed a breakpoint in the method dataGridView1_DragDrop to see whether this method gets called at all. I just want to be certain the problem does not occur further on, for instance in "addFiles".
Yeah, i placed a breakpoint in the dataGridView1_DragDrop method and tested it. But the method is not invoking when files are dragged and dropped from the openFileDialog box. Phanindra...
-
Yeah, i placed a breakpoint in the dataGridView1_DragDrop method and tested it. But the method is not invoking when files are dragged and dropped from the openFileDialog box. Phanindra...
-
Does your DragEnter event handler get invoked? What kind of cursor do you get when you drag from the OpenFileDialog and what kind when you drag from Windows Explorer?
no DragEnter event handler is not invoked for openFileDialog Box. I am getting a rectangle cursor with the pointer when dragged from windows explorer and default cursor like circle with a bar in it when dragged from openFileDialog box Phanindra...
-
no DragEnter event handler is not invoked for openFileDialog Box. I am getting a rectangle cursor with the pointer when dragged from windows explorer and default cursor like circle with a bar in it when dragged from openFileDialog box Phanindra...
I think I know what's going on. When I tested my own application I noticed something strange. When I drag from Explorer, the individual controls in my application react to drag-drop events. However, when I drag from an OpenFileDialog the controls do not respond, but the Form they are on does! (I should mention that in my case the Form happens to have AllowDrop set to true.) What you can do is to add event handlers for DragEnter and DragDrop to your application Form. In these event handlers check which control the mouse cursor is on (e.g. using the position given in the DragEventArgs) and re-route the event to that control.
-
I think I know what's going on. When I tested my own application I noticed something strange. When I drag from Explorer, the individual controls in my application react to drag-drop events. However, when I drag from an OpenFileDialog the controls do not respond, but the Form they are on does! (I should mention that in my case the Form happens to have AllowDrop set to true.) What you can do is to add event handlers for DragEnter and DragDrop to your application Form. In these event handlers check which control the mouse cursor is on (e.g. using the position given in the DragEventArgs) and re-route the event to that control.
Actually the thing is here that i am using windows user control. But still DragEnter and DragDrop events are not invoked in my application. I made AllwDrop of user control to True. But no use. Phanindra...
-
Actually the thing is here that i am using windows user control. But still DragEnter and DragDrop events are not invoked in my application. I made AllwDrop of user control to True. But no use. Phanindra...
It seems the application Form is the only "control" that is able to receive drag-drop events when an OpenFileDialog is open (with the OpenFileDialog belonging to that application). If you do not "own" this Form, for instance if you are developing a user control for distribution, then I'm afraid you can't do what you intent to do. Sorry :^).
-
It seems the application Form is the only "control" that is able to receive drag-drop events when an OpenFileDialog is open (with the OpenFileDialog belonging to that application). If you do not "own" this Form, for instance if you are developing a user control for distribution, then I'm afraid you can't do what you intent to do. Sorry :^).
Thats OK. Thanks U. Thanks for ur cooperation:) Phanindra...