473,226 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

Drag'n'drop - GiveFeedback event never called

I am trying to implement drag and drop in a C# app, but for some reason I
can't get it to call the GiveFeedback event. I have done everything by the
book as far as I can tell, but a breakpoint in the GiveFeedback event is
simply never reached. I know that's not much to go on, but if anyone can
suggest what I might have missed I'd be very grateful.
--
Dave
Jan 14 '06 #1
6 10967
Dave, maybe you can show us some sample code that exemplifies the problem?
e.g. the call(s) to DoDragDrop(), definition of your event handler and how
you're adding the delegate to the event?

--
http://www.peterRitchie.com/
"Dave" wrote:
I am trying to implement drag and drop in a C# app, but for some reason I
can't get it to call the GiveFeedback event. I have done everything by the
book as far as I can tell, but a breakpoint in the GiveFeedback event is
simply never reached. I know that's not much to go on, but if anyone can
suggest what I might have missed I'd be very grateful.


Jan 14 '06 #2
OK. Here goes. I'll try and keep it brief while hopefully including
everything important. I'm actually using drag and drop to implement a bar
control (as a UserControl) that can be picked up at either end and shortened
or lengthened. Thre is a set of bars, each bar is made up of a row of
buttons, the whole being implemnted as a 2-dim array of Button objects.
Because of the way it works the DragDrop event is not required. There are
also no DragOver or DragQueryContinue events implemented. I want to use
GiveFeedback in order to set a two-headed arrow cursor.
So:
// FormLoad event creates the buttons in ButtonArray:
ButtonArray = new Button[Rows, Columns];
for (int row = 0; row < Rows; row++)
{
for (int col = 0; col < Columns; col++)
{
ButtonArray[row, col] = new Button();
// Stuff to set up the button, size location etc. Omitted.
ButtonArray[row, col].MouseDown +=
new MouseEventHandler(Button_MouseDown);
ButtonArray[row, col].DragEnter +=
new DragEventHandler(Button_DragEnter);
ButtonArray[row, col].GiveFeedback +=
new GiveFeedbackEventHandler(Button_GiveFeedback);
ButtonArray[row, col].AllowDrop = true;
Controls.Add(ButtonArray[row, col]);
}
}

//Drag and drop starts in the MouseDown event:
private void Button_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Stuff to check the cursor is at the end of a row, etc. Omitted.
DoDragDrop(sender, DragDropEffects.Move);
// DragDrop effect is irrelevant for my purpose, but I have tried
various values.
// I can change which of the standard cursors is displayed, but not
get it to call
// GiveFeedback
}
}

private void Button_DragEnter(object sender, DragEventArgs e)
{
// Check that the cursor is still in the same row
if (GetRow((Button)sender) ==
GetRow((Button)e.Data.GetData(typeof(Button))))
{
// Stuff to work out which direction the cursor is moving and change
the colour
// of the buttons. Omitted.
e.Effect = e.AllowedEffect; // Allows whatever effect I set in
MouseDown
}
else
{
e.Effect = DragDropEffects.None; // Shows a No Entry cursor
}
}

private void Button_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
bool setBreakpointHere = true; // Never reached
}

Hope that helps. Thanks for taking a look.
--
Dave
"Peter Ritchie" wrote:
Dave, maybe you can show us some sample code that exemplifies the problem?
e.g. the call(s) to DoDragDrop(), definition of your event handler and how
you're adding the delegate to the event?

--
http://www.peterRitchie.com/
"Dave" wrote:
I am trying to implement drag and drop in a C# app, but for some reason I
can't get it to call the GiveFeedback event. I have done everything by the
book as far as I can tell, but a breakpoint in the GiveFeedback event is
simply never reached. I know that's not much to go on, but if anyone can
suggest what I might have missed I'd be very grateful.

Jan 15 '06 #3
Hi Dave. DoDragDrop() and the GiveFeedback event apply to a particular
control, in unison. If you're calling DoDragDrop() on your Form control, the
GiveFeedback handler needs to be linked to the form (instead or as well).
You're linking the GiveFeedback handler to the each of the buttons. Since
you're not calling DoDragDrop on one of the buttons, it will not have the
opportunity to provide feedback on that drag-drop operation. i.e. since a
button hasn't performed the drag-drop it can't provide feedback.

Alternatively, in your MouseDown handler you could get the button to which
the event applies by casting the sender object to a Button object (e.g.
Button button = sender As Button) and calling DoDragDrop for the button
object (e.g. button.DoDragDrop(this, DragDropEffects.Move) or
button.DoDragDrop(sender, DragDropEffects.Move))

--
http://www.peterRitchie.com/
"Dave" wrote:
OK. Here goes. I'll try and keep it brief while hopefully including
everything important. I'm actually using drag and drop to implement a bar
control (as a UserControl) that can be picked up at either end and shortened
or lengthened. Thre is a set of bars, each bar is made up of a row of
buttons, the whole being implemnted as a 2-dim array of Button objects.
Because of the way it works the DragDrop event is not required. There are
also no DragOver or DragQueryContinue events implemented. I want to use
GiveFeedback in order to set a two-headed arrow cursor.
So:
// FormLoad event creates the buttons in ButtonArray:
ButtonArray = new Button[Rows, Columns];
for (int row = 0; row < Rows; row++)
{
for (int col = 0; col < Columns; col++)
{
ButtonArray[row, col] = new Button();
// Stuff to set up the button, size location etc. Omitted.
ButtonArray[row, col].MouseDown +=
new MouseEventHandler(Button_MouseDown);
ButtonArray[row, col].DragEnter +=
new DragEventHandler(Button_DragEnter);
ButtonArray[row, col].GiveFeedback +=
new GiveFeedbackEventHandler(Button_GiveFeedback);
ButtonArray[row, col].AllowDrop = true;
Controls.Add(ButtonArray[row, col]);
}
}

//Drag and drop starts in the MouseDown event:
private void Button_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Stuff to check the cursor is at the end of a row, etc. Omitted.
DoDragDrop(sender, DragDropEffects.Move);
// DragDrop effect is irrelevant for my purpose, but I have tried
various values.
// I can change which of the standard cursors is displayed, but not
get it to call
// GiveFeedback
}
}

private void Button_DragEnter(object sender, DragEventArgs e)
{
// Check that the cursor is still in the same row
if (GetRow((Button)sender) ==
GetRow((Button)e.Data.GetData(typeof(Button))))
{
// Stuff to work out which direction the cursor is moving and change
the colour
// of the buttons. Omitted.
e.Effect = e.AllowedEffect; // Allows whatever effect I set in
MouseDown
}
else
{
e.Effect = DragDropEffects.None; // Shows a No Entry cursor
}
}

private void Button_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
bool setBreakpointHere = true; // Never reached
}


Jan 15 '06 #4
Wow. I never would have figured that out (the way the example in the help is
put together I don't think that point is really illustrated, or maybe I just
missed it.) Big thanks. I'll give it a go.
I can't see any particular reason to do it one way rather than the other
(call and event both in the control or both in the button), can you?
--
Dave
"Peter Ritchie" wrote:
Hi Dave. DoDragDrop() and the GiveFeedback event apply to a particular
control, in unison. If you're calling DoDragDrop() on your Form control, the
GiveFeedback handler needs to be linked to the form (instead or as well).
You're linking the GiveFeedback handler to the each of the buttons. Since
you're not calling DoDragDrop on one of the buttons, it will not have the
opportunity to provide feedback on that drag-drop operation. i.e. since a
button hasn't performed the drag-drop it can't provide feedback.

Alternatively, in your MouseDown handler you could get the button to which
the event applies by casting the sender object to a Button object (e.g.
Button button = sender As Button) and calling DoDragDrop for the button
object (e.g. button.DoDragDrop(this, DragDropEffects.Move) or
button.DoDragDrop(sender, DragDropEffects.Move))

--
http://www.peterRitchie.com/
"Dave" wrote:
OK. Here goes. I'll try and keep it brief while hopefully including
everything important. I'm actually using drag and drop to implement a bar
control (as a UserControl) that can be picked up at either end and shortened
or lengthened. Thre is a set of bars, each bar is made up of a row of
buttons, the whole being implemnted as a 2-dim array of Button objects.
Because of the way it works the DragDrop event is not required. There are
also no DragOver or DragQueryContinue events implemented. I want to use
GiveFeedback in order to set a two-headed arrow cursor.
So:
// FormLoad event creates the buttons in ButtonArray:
ButtonArray = new Button[Rows, Columns];
for (int row = 0; row < Rows; row++)
{
for (int col = 0; col < Columns; col++)
{
ButtonArray[row, col] = new Button();
// Stuff to set up the button, size location etc. Omitted.
ButtonArray[row, col].MouseDown +=
new MouseEventHandler(Button_MouseDown);
ButtonArray[row, col].DragEnter +=
new DragEventHandler(Button_DragEnter);
ButtonArray[row, col].GiveFeedback +=
new GiveFeedbackEventHandler(Button_GiveFeedback);
ButtonArray[row, col].AllowDrop = true;
Controls.Add(ButtonArray[row, col]);
}
}

//Drag and drop starts in the MouseDown event:
private void Button_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Stuff to check the cursor is at the end of a row, etc. Omitted.
DoDragDrop(sender, DragDropEffects.Move);
// DragDrop effect is irrelevant for my purpose, but I have tried
various values.
// I can change which of the standard cursors is displayed, but not
get it to call
// GiveFeedback
}
}

private void Button_DragEnter(object sender, DragEventArgs e)
{
// Check that the cursor is still in the same row
if (GetRow((Button)sender) ==
GetRow((Button)e.Data.GetData(typeof(Button))))
{
// Stuff to work out which direction the cursor is moving and change
the colour
// of the buttons. Omitted.
e.Effect = e.AllowedEffect; // Allows whatever effect I set in
MouseDown
}
else
{
e.Effect = DragDropEffects.None; // Shows a No Entry cursor
}
}

private void Button_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
bool setBreakpointHere = true; // Never reached
}

Jan 16 '06 #5
Hi Dave. Yes, it's not clear from the documentation; it took me more than
one try...

If I were subclassing a control, I may be inclined to have the control deal
with the drag-drop (in that case you should be dealing with overrides and not
events). Since you're not subclassing Button, I would suggest just letting
the Form-based class deal with the drag-drop. e.g continue with DoDragDrop()
from the Form's Button_MouseDown() but link the GiveFeedback event handler to
your Form class. I'm assuming the parent of the buttons is a Form-based
class...

--
http://www.peterRitchie.com/
"Dave" wrote:
Wow. I never would have figured that out (the way the example in the help is
put together I don't think that point is really illustrated, or maybe I just
missed it.) Big thanks. I'll give it a go.
I can't see any particular reason to do it one way rather than the other
(call and event both in the control or both in the button), can you?
--
Dave
"Peter Ritchie" wrote:
Hi Dave. DoDragDrop() and the GiveFeedback event apply to a particular
control, in unison. If you're calling DoDragDrop() on your Form control, the
GiveFeedback handler needs to be linked to the form (instead or as well).
You're linking the GiveFeedback handler to the each of the buttons. Since
you're not calling DoDragDrop on one of the buttons, it will not have the
opportunity to provide feedback on that drag-drop operation. i.e. since a
button hasn't performed the drag-drop it can't provide feedback.

Alternatively, in your MouseDown handler you could get the button to which
the event applies by casting the sender object to a Button object (e.g.
Button button = sender As Button) and calling DoDragDrop for the button
object (e.g. button.DoDragDrop(this, DragDropEffects.Move) or
button.DoDragDrop(sender, DragDropEffects.Move))

--
http://www.peterRitchie.com/
"Dave" wrote:
OK. Here goes. I'll try and keep it brief while hopefully including
everything important. I'm actually using drag and drop to implement a bar
control (as a UserControl) that can be picked up at either end and shortened
or lengthened. Thre is a set of bars, each bar is made up of a row of
buttons, the whole being implemnted as a 2-dim array of Button objects.
Because of the way it works the DragDrop event is not required. There are
also no DragOver or DragQueryContinue events implemented. I want to use
GiveFeedback in order to set a two-headed arrow cursor.
So:
// FormLoad event creates the buttons in ButtonArray:
ButtonArray = new Button[Rows, Columns];
for (int row = 0; row < Rows; row++)
{
for (int col = 0; col < Columns; col++)
{
ButtonArray[row, col] = new Button();
// Stuff to set up the button, size location etc. Omitted.
ButtonArray[row, col].MouseDown +=
new MouseEventHandler(Button_MouseDown);
ButtonArray[row, col].DragEnter +=
new DragEventHandler(Button_DragEnter);
ButtonArray[row, col].GiveFeedback +=
new GiveFeedbackEventHandler(Button_GiveFeedback);
ButtonArray[row, col].AllowDrop = true;
Controls.Add(ButtonArray[row, col]);
}
}

//Drag and drop starts in the MouseDown event:
private void Button_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Stuff to check the cursor is at the end of a row, etc. Omitted.
DoDragDrop(sender, DragDropEffects.Move);
// DragDrop effect is irrelevant for my purpose, but I have tried
various values.
// I can change which of the standard cursors is displayed, but not
get it to call
// GiveFeedback
}
}

private void Button_DragEnter(object sender, DragEventArgs e)
{
// Check that the cursor is still in the same row
if (GetRow((Button)sender) ==
GetRow((Button)e.Data.GetData(typeof(Button))))
{
// Stuff to work out which direction the cursor is moving and change
the colour
// of the buttons. Omitted.
e.Effect = e.AllowedEffect; // Allows whatever effect I set in
MouseDown
}
else
{
e.Effect = DragDropEffects.None; // Shows a No Entry cursor
}
}

private void Button_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
bool setBreakpointHere = true; // Never reached
}

Jan 16 '06 #6
That's what I've done, and it seeme to work fine. Many thanks
--
Dave
"Peter Ritchie" wrote:
Hi Dave. Yes, it's not clear from the documentation; it took me more than
one try...

If I were subclassing a control, I may be inclined to have the control deal
with the drag-drop (in that case you should be dealing with overrides and not
events). Since you're not subclassing Button, I would suggest just letting
the Form-based class deal with the drag-drop. e.g continue with DoDragDrop()
from the Form's Button_MouseDown() but link the GiveFeedback event handler to
your Form class. I'm assuming the parent of the buttons is a Form-based
class...

--
http://www.peterRitchie.com/
"Dave" wrote:
Wow. I never would have figured that out (the way the example in the help is
put together I don't think that point is really illustrated, or maybe I just
missed it.) Big thanks. I'll give it a go.
I can't see any particular reason to do it one way rather than the other
(call and event both in the control or both in the button), can you?
--
Dave
"Peter Ritchie" wrote:
Hi Dave. DoDragDrop() and the GiveFeedback event apply to a particular
control, in unison. If you're calling DoDragDrop() on your Form control, the
GiveFeedback handler needs to be linked to the form (instead or as well).
You're linking the GiveFeedback handler to the each of the buttons. Since
you're not calling DoDragDrop on one of the buttons, it will not have the
opportunity to provide feedback on that drag-drop operation. i.e. since a
button hasn't performed the drag-drop it can't provide feedback.

Alternatively, in your MouseDown handler you could get the button to which
the event applies by casting the sender object to a Button object (e.g.
Button button = sender As Button) and calling DoDragDrop for the button
object (e.g. button.DoDragDrop(this, DragDropEffects.Move) or
button.DoDragDrop(sender, DragDropEffects.Move))

--
http://www.peterRitchie.com/
"Dave" wrote:

> OK. Here goes. I'll try and keep it brief while hopefully including
> everything important. I'm actually using drag and drop to implement a bar
> control (as a UserControl) that can be picked up at either end and shortened
> or lengthened. Thre is a set of bars, each bar is made up of a row of
> buttons, the whole being implemnted as a 2-dim array of Button objects.
> Because of the way it works the DragDrop event is not required. There are
> also no DragOver or DragQueryContinue events implemented. I want to use
> GiveFeedback in order to set a two-headed arrow cursor.
> So:
> // FormLoad event creates the buttons in ButtonArray:
> ButtonArray = new Button[Rows, Columns];
> for (int row = 0; row < Rows; row++)
> {
> for (int col = 0; col < Columns; col++)
> {
> ButtonArray[row, col] = new Button();
> // Stuff to set up the button, size location etc. Omitted.
> ButtonArray[row, col].MouseDown +=
> new MouseEventHandler(Button_MouseDown);
> ButtonArray[row, col].DragEnter +=
> new DragEventHandler(Button_DragEnter);
> ButtonArray[row, col].GiveFeedback +=
> new GiveFeedbackEventHandler(Button_GiveFeedback);
> ButtonArray[row, col].AllowDrop = true;
> Controls.Add(ButtonArray[row, col]);
> }
> }
>
> //Drag and drop starts in the MouseDown event:
> private void Button_MouseDown(object sender, MouseEventArgs e)
> {
> if (e.Button == MouseButtons.Left)
> {
> // Stuff to check the cursor is at the end of a row, etc. Omitted.
> DoDragDrop(sender, DragDropEffects.Move);
> // DragDrop effect is irrelevant for my purpose, but I have tried
> various values.
> // I can change which of the standard cursors is displayed, but not
> get it to call
> // GiveFeedback
> }
> }
>
> private void Button_DragEnter(object sender, DragEventArgs e)
> {
> // Check that the cursor is still in the same row
> if (GetRow((Button)sender) ==
> GetRow((Button)e.Data.GetData(typeof(Button))))
> {
> // Stuff to work out which direction the cursor is moving and change
> the colour
> // of the buttons. Omitted.
> e.Effect = e.AllowedEffect; // Allows whatever effect I set in
> MouseDown
> }
> else
> {
> e.Effect = DragDropEffects.None; // Shows a No Entry cursor
> }
> }
>
> private void Button_GiveFeedback(object sender, GiveFeedbackEventArgs e)
> {
> bool setBreakpointHere = true; // Never reached
> }

Jan 17 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: VR | last post by:
I am trying to use a custom cursor during drag-drop operation between 2 ListViews. So, I have a code that at the time GiveFeedback() is called creates a new cursor based on the icon and text of...
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
4
by: Sam Martin | last post by:
hi all i have a user control which consumes the doubleclick event. when i use this control and implement drag and drop functionality, i.e. on mousedown check that the left button has been...
8
by: benkial | last post by:
I am writing a small GUI tool in C#, and I want to experiment some fancy trick as follows: when the user click on a "OK" button, the code will initiate a "Drag and Drop" operation in the GUI itself...
0
by: RHSFSS | last post by:
Hi, I have a Drag and Drop registration problem (See http://www.thescripts.com/forum/thread434707.html for similar problem post), can anyone out thereadvise on the best solution? I have a .NET 2.0 ...
1
by: auad | last post by:
hi, I'm writing an application like windows explorer and I want to know how to implement that kind of "file shadow" that appears when you drag items in a listview. I read that I have to implement...
0
by: auad | last post by:
hi, I'm writing an application like windows explorer and I want to know how to implement that kind of "file shadow" that appears under the mouse cursor when you drag items in a listview. I read...
5
by: empiresolutions | last post by:
Hello Fellow Developers, I am using the awesome drag and drop script found at http://script.aculo.us/. I have also added a modification that interacts to a db for reordering upon release of a...
5
by: Romulo NF | last post by:
Greetings, Im back here to show the new version of the drag & drop table columns (original script ). Ive found some issues with the old script, specially when trying to use 2 tables with...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.