473,385 Members | 2,014 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,385 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 11014
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, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.